Getting Started: Basic Usage of JDBC

esProc 4 0

esProc can be embedded into Java program. So the latter can call the cellset program written in esProc using a way of connection such as JDBC. The method of calling the esProc program is the same as that of calling the stored procedure. The following is a brief introduction to esProc JDBC. 

1. Description of the jars of esProc JDBC

esProc JDBC is like an incomplete database JDBC driver without physical tables. It can be regarded simply as a database that only supports the stored procedure. In addition, it is a built-in computing engine, thus no standalone servers are needed. 

esProc JDBC has three basic jars, which are all situated in \esProc\ lib in installation directory:

       dm.jar                                           esProc computing engine and JDBC driver

       icu4j_3_4_5.jar                              handle internationalization

       dom4j-1.6.1.jar                              parse the configuration files 

If other databases are to be used as the datasources of esProc JDBC, then the driver jars of these databases are required to be in place. For example, hsqldb.jar is necessary to use the demo database. Please note the esProc JDBC requires JDK1.6 or higher versions. 

2. Basic usage of esProc JDBC

In the cellset code, the result set is returned by result statement.

  A
1 =connect(“demo”)
2 =A1.query(“select * from EMPLOYEE where EID=?”,arg1)
3 >A1.close()
4 return A2

In the application code, arg1 is a cellset parameter. This dfx file will be named as test.dfx

Note: The result set of dfx is returned by return (or result ) statement. When dfx is called, the parameter names that receive the parameters won’t be used; the values of parameters will be assigned according to their order instead. 

1)  Load the jars to be used. Load the basic jars of esProc JDBC mentioned above while launching the Java application. These jars can be put in the directory of WEB-INF/lib under a web application.

2)   Deploy dfxConfig.xml, config.xml and the dfx file

Prepare file config.xml, which contains the basic configuration information of esProc, such as registration code, searching path, datasource configuration, etc. The file can be found in the path esProc\config in esProc’s installation directory. The information in it is the same as that set in the esProc Option page. The configuration is allowed to be adjusted before deployment (like modifying the Searching path which is used to search the dfx file):

esProc_start_jdbc_2

Or the datasources necessary for dfx can be configured in the Data Source Explorer: 

esProc_start_jdbc_3

After the modification, config.xml and dfxConfig.xml, which are situated in esProc\classes in the esProc’s installation directory, will be saved in the class path of the application that will use them. 

Put the test.dfx created in Step 1 in the class path of the application, or put it in the path specified by file dfxConfig.xml’s <paths/> node (i.e. the above-mentioned Searching path).

3) Further configure file dfxConfig.xml manually if necessary. For detailed operation, please refer to related documents. Please note the name of configured file should still be dfxConfig.xml and must not be changed.

4)   Call dfx in Java program. 

public void testDataServer(){

              Connection con = null;

              com.esproc.jdbc.InternalCStatement st;

              com.esproc.jdbc.InternalCStatement st2;

              try{

                     //create a connection

                     Class.forName(“com.esproc.jdbc.InternalDriver”);

                     con= DriverManager.getConnection(“jdbc:esproc:local://”);

                     //call the stored procedure in which test is the name of dfx file

                     st =(com. esproc.jdbc.InternalCStatement)con.prepareCall(“call test(?)”);

                     //set the parameters

                     st.setObject(1,”3″);

                     //the result obtained by executing the following code is the same as that obtained using the above calling method

                     st =(com. esproc.jdbc.InternalCStatement)con.prepareCall(“call test(3)”);

                     //execute the stored procedure

                     st.execute();

                     //get result set

                     ResultSet set = st.getResultSet();

}

              catch(Exception e){

                     System.out.println(e);

              }

              finally{

                     //close the connection

                     if (con!=null) {

                            try {

                                   con.close();

                            }

                            catch(Exception e) {

                                   System.out.println(e);

                            }

                     }

              }

} 

To know more about calling methods and configuration, please refer to documents that cover a more in-depth discussion at this point. 

FAVOR (0)
Leave a Reply
Cancel
Icon

Hi,You need to fill in the Username and Email!

  • Username (*)
  • Email (*)
  • Website