Using Transaction Utility Methods for Testing and Debugging

The Transaction interface provides utility methods for testing and debugging queries and applications, including:

Using dumpQueryResult

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);
}

Using executeCommand

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.