Interacting with databases by using the JavaCompute node
Access databases from Java™ code included in the JavaCompute node.
About this task
If you use JDBCProvider for type 4 connections or MbSQLStatement, the databases that you access can participate in globally coordinated transactions. In all other cases, database access cannot be globally coordinated.
MbSQLStatement
About this task
The MbSQLStatement class provides full transactional database access by using ESQL and ODBC. Global coordination is provided by IBM® MQ on distributed systems, and by RRS on z/OS®.
- Calling select() on this object returns the results of the query.
- Calling execute() on this object runs a query where no results are returned, such as updating a table.
MbMessage newMsg = new MbMessage(assembly.getMessage());
MbMessageAssembly newAssembly = new MbMessageAssembly(assembly, newMsg);
String table = "dbTable";
MbSQLStatement state = createSQLStatement( "dbName",
"SET OutputRoot.XMLNS.integer[] = PASSTHRU('SELECT * FROM " + table + "');" );
state.setThrowExceptionOnDatabaseError(false);
state.setTreatWarningsAsErrors(true);
state.select( assembly, newAssembly );
int sqlCode = state.getSQLCode();
if(sqlCode != 0)
{
// Do error handling here
}
getOutputTerminal("out").propagate(assembly);
JDBC API in an unmanaged environment
About this task
You can access standard Java APIs in the code that you write for your JavaCompute nodes, including JDBC calls. Therefore, you can use JDBC APIs to connect to a database, write to or read from the database, and disconnect from the database. On operating systems other than z/OS, your JDBC connection code can call both type 2 and type 4 JDBC drivers in this environment, but they are not supplied. You must obtain these drivers from your database vendor. On z/OS, type 2 drivers are not supported.
If you choose this method to access databases, managing the transactions is not supported; your code must manage the local commit and rollback of database changes. Your code must also manage the connection lifecycle, connection thread affinity, and connection pooling. You must also monitor the access to databases when you use this technique to ensure that these connections do not cause interference with connections that are made by the integration server. In particular, be aware that type 2 drivers bridge to an ODBC connection that might be in use in message flows that access databases from ESQL.
SQLJ
About this task
Procedure
Create an SQLJ file within a Java project by completing the following steps: