WebSphere Message Brokers
File: ac30494_
Writer: Catherine Tucker

Task topic

This build: July 31, 2007 21:20:17

Interacting with databases using the JavaCompute node

This topic describes how to access databases using the JavaCompute node.

You can access databases from the JavaCompute node using only the following techniques:

The broker resource manager does not coordinate database access when using type 2 or type 4 JDBC drivers, or SQLJ. Only the MbSQLStatement is fully supported. Types 2 and 4 JDBC drivers are supported, but the drivers are not provided with the broker.

MbSQLStatement

The MbSQLStatement class provides full transactional database access using ESQL. Create instances of this class using the createSQLStatement() method of MbNode, passing in the ODBC datasource, a broker EQSL statement, and optionally the transaction mode to the method.
  • Calling select() on this object returns the results of the query.
  • Calling execute() on this object executes a query where no results are returned, such as updating a table.
The following Java™ code shows how to access a database using MbSQLStatement:
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); 

SQLJ

SQLJ is a Java extension allowing static SQL statements to be embedded within Java code. The broker resource manager does not coordinate database access when using SQLJ.
  1. Follow these steps to enable SQLJ capability within the broker tooling:
    1. Select Window > Preferences.
    2. Expand Workbench.
    3. Select Capabilities.
    4. Expand Database Developer.
    5. Select the SQLJ Development check box.
    6. Click OK.
  2. Then follow these steps to create a new SQLJ file within a Java project:
    1. Right-click the Java project in which you want to create the file.
    2. Select New > Other....
    3. Expand Data.
    4. Expand SQLJ.
    5. Select SQLJ File.
    6. Click Next.
    7. Follow the directions given by the New SQLJ File wizard to generate the SQLJ file.
You can now reference the class in this SQLJ file from a JavaCompute node class in this project or in another referenced project.

Type 2 and type 4 JDBC drivers

The broker resource manager does not coordinate database access when using type 2 or type 4 JDBC drivers. Types 2 and 4 JDBC drivers are supported, but the drivers are not provided with the broker.

Related concepts
Project references
Related reference
JavaCompute node
Notices | Trademarks | Downloads | Library | Support | Feedback

Copyright IBM Corporation 1999, 2007Copyright IBM Corporation 1999, 2007. All Rights Reserved.
This build: July 31, 2007 21:20:17

ac30494_ This topic's URL is: