Wednesday, October 22, 2014

Execute DB Queries inside Mapper

Even its not encourage to execute direct SQL queries inside the MEC mapper due to performance issue, but If you don't have any other soluion (from APIs for WebServices) rather than that,  you can call DB queries inside the map.

This is not the "Database" tool available in Mapper toolbar. Inside a Java function you can use below to pull some value from the database.

String sql = "SELECT CFFACI FROM "+schema+".CFACIL WHERE CFCONO="+CONO+" AND CFFANM = "+locationCode;

String FACI = "";

 java.sql.Connection con =        
    com.intentia.ec.db.ConnectionPool.getConnection();
 java.sql.Statement stmt = con.createStatement();
 java.sql.ResultSet rs = stmt.executeQuery(sql);

 if (rs.next()) 
 {
    FACI = rs.getString("FACI").trim();
 }

 rs.close(); 
 stmt.close();

6 comments :