The Transaction interface provides utility methods for testing and debugging queries and applications, including:
dumpQueryResult This method writes the result of the query to a (potentially very long) string. It takes three parameters: the first is the SQL query statement. The second is the class that dumps the result to a string. This class must implement the oracle.jbo.server.QueryDump interface. The implementation of this class decides what to do with the third parameter (which can be null). The Business Components for Java framework provides these methods:
oracle.jbo.server.QueryDumpCSV(), which dumps the query result as a comma-separated BASIC text format. This method is not practical if the query generates a large result set.
oracle.jbo.server.QueryDumpTab() which dumps the query results in a tab-separated text format.
executeCommand This method takes one parameter: a valid SQL statement to be executed by the server. The return value tells how many rows were affected by the SQL statement.
The following code example uses dumpQueryResult.
public static void demoSimpleFetch(ApplicationModule appMod) {
// Define and execute a simple SQL statement.
String sqlStr = "SELECT Emp.ename FROM EMP Emp ";
// dumpQueryResult is a utility method for testing queries.
String result = appMod.getTransaction().dumpQueryResult(sqlStr,
"oracle.jbo.server.QueryDumpTab",
null);
System.out.println(sqlStr);
System.out.println(result);
}
The following code example uses executeCommand. The SQL string is designed to update the EMP table. This example passes the string to executeCommand, then prints a message to report how many rows were actually updated.
public static void demoUpdateColumn(ApplicationModule appMod) {
String sqlStr = "UPDATE EMP " +
"SET MGR=7007 " +
"WHERE MGR=7698 ";
int n = appMod.getTransaction().executeCommand(sqlStr);
System.out.println("Updated " + n + " rows.");
}
Be careful when using executeCommand, because it will execute any valid SQL statement. For example, you could perform an operation like the following DDL command:
appMod.getTransaction().executeCommand("DROP TABLE MYTEMPTABLE");
A pending database transaction could be committed inadvertently due to the implicit commit performed by DDL operations, as well as having any row locks released.