public class MbSQLStatement extends Object
createSQLStatement()
methods of MbNode.
Example usage:
public void evaluate(MbMessageAssembly assembly, MbInputTerminal inTerm) throws MbException { MbMessage newMsg = new MbMessage(assembly.getMessage()); MbMessageAssembly newAssembly = new MbMessageAssembly(assembly, newMsg); String table = assembly.getMessage().getRootElement().getLastChild().getFirstChild().getName(); 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 System.out.println("sqlCode = " + sqlCode); System.out.println("sqlNativeError = " + state.getSQLNativeError()); System.out.println("sqlState = " + state.getSQLState()); System.out.println("sqlErrorText = " + state.getSQLErrorText()); } getOutputTerminal("out").propagate(assembly); }Database access using JDBC is not supported.
Modifier and Type | Field and Description |
---|---|
static int |
SQL_TRANSACTION_AUTO
Transaction type.
|
static int |
SQL_TRANSACTION_COMMIT
Transaction type.
|
Modifier and Type | Method and Description |
---|---|
void |
clearStatement()
Clears the statement.
|
void |
execute(MbMessageAssembly assembly)
Executes the SQL expression associated with this object.
|
String |
getDataSourceName()
Gets the ODBC data source name associated with this SQL statement
object.
|
int |
getSQLCode()
|
String |
getSQLErrorText()
|
int |
getSQLNativeError()
|
String |
getSQLState()
|
String |
getStatement()
Gets the SQL expression associated with this SQL statement object.
|
boolean |
getThrowExceptionOnDatabaseError() |
int |
getTransactionType()
Gets the transaction type of this SQL statement object.
|
boolean |
getTreatWarningsAsErrors() |
void |
select(MbMessageAssembly assemblyIn,
MbMessageAssembly assemblyOut)
Executes the SQL expression associated with this object.
|
void |
setThrowExceptionOnDatabaseError(boolean throwExceptions)
Sets the value of the 'throwExceptionOnDatabaseError' attribute.
|
void |
setTreatWarningsAsErrors(boolean warningsAsErrors)
Sets the value of the 'treatWarningAsErrors' attribute.
|
String |
toString() |
public static final int SQL_TRANSACTION_AUTO
public static final int SQL_TRANSACTION_COMMIT
public int getTransactionType() throws MbException
execute
or
select
method (that is, the message flow is partially broker coordinated).MbException
public String getDataSourceName() throws MbException
MbException
public String getStatement() throws MbException
MbException
public void clearStatement() throws MbException
MbException
public void execute(MbMessageAssembly assembly) throws MbException
If a database error occurs during the execution of this statement,
the behavior is determined by the value of the
'throwExceptionOnDatabaseError' attribute. If set to true
(the default value), an exception gets thrown which can be caught
if run within a try/catch block. If set to true using
setThrowExceptionOnDatabaseError()
then no exception is thrown, but the SQLCode must be examined
determine status. The four database state values are available using
getSQLCode()
,
getSQLState()
,
getSQLNativeError()
, and
getSQLErrorText()
assembly
- The MbMessageAssembly in which any data referenced by
the SQL expression is held.MbException
public void select(MbMessageAssembly assemblyIn, MbMessageAssembly assemblyOut) throws MbException
If a database error occurs during the execution of this statement,
the behavior is determined by the value of the
'throwExceptionOnDatabaseError' attribute. If set to true
(the default value), an exception gets thrown which can be caught
if run within a try/catch block. If set to true using
setThrowExceptionOnDatabaseError()
then no exception is thrown, but the SQLCode must be examined
determine status. The four database state values are available using
getSQLCode()
,
getSQLState()
,
getSQLNativeError()
, and
getSQLErrorText()
assemblyIn
- The MbMessageAssembly in which any data referenced by
the SQL expression is held.assemblyOut
- The MbMessageAssembly into which any data returned
by the SQL expression will be written.MbException
public void setThrowExceptionOnDatabaseError(boolean throwExceptions)
getSQLCode()
,
getSQLState()
,
getSQLNativeError()
, and
getSQLErrorText()
.
By default, this attribute is set to 'true'.
throwExceptions
- The boolean value to be set.public boolean getThrowExceptionOnDatabaseError()
public void setTreatWarningsAsErrors(boolean warningsAsErrors)
warningsAsErrors
- The boolean value to be set.public boolean getTreatWarningsAsErrors()
public int getSQLCode()
select()
or
execute()
call.
This method only returns a valid value if 'throwExceptionOnDatabaseError'
was set to false prior to the select() or execute() call.
This must be called to determine the success/failure status of the
database call.public int getSQLNativeError()
select()
or
execute()
call.
This method only returns a valid value if 'throwExceptionOnDatabaseError'
was set to false prior to the select() or execute() call.public String getSQLState()
select()
or
execute()
call.
This method only returns a valid value if 'throwExceptionOnDatabaseError'
was set to false prior to the select() or execute() call.public String getSQLErrorText()
select()
or
execute()
call.
This method only returns a valid value if 'throwExceptionOnDatabaseError'
was set to false prior to the select() or execute() call.