Interacting with databases using the JavaCompute node

You can access databases from the JavaCompute node using only the following methods:
  • MbSQLStatement
  • Type 4 JDBC drivers

The broker resource manager does not coordinate database access when using type 4 JDBC drivers.

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.XML.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); 
Related reference
JavaCompute node