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, itisa built-in computing engine, thus no
standalone servers are needed.
esProc JDBC has five basic jars, which are all situated in \esProc\ lib in installation directory:
dm.jar esProc
computing engine and JDBC driver
poi-3.7-20101029.jar process
the access of Excel files
log4j_128.jar process logs
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.
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 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.
a.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/libunder a
web application.
b. 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\configin 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):
Or the datasources necessary for dfxcan
be configured in the Data Source Explorer:
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).
a. 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.
b. Call dfx in Java program.
publicvoid testDataServer(){
Connection
con = null;
com.esproc.jdbc.InternalCStatementst;
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("calltest(?)");
//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);
}
}
}
}
没有评论:
发表评论