JuhaM wrote:
Hi All
Just wondering if its possible get more descriptive error messages in
to com.ibm.db2.jcc.b.SqlException. getMessge or toString() methods
gives only SQL-error codes like:
SQLCODE: -1218, SQLSTATE: 57011, SQLERRMC: 4096
You can do this (following the description here:
http://publib.boulder.ibm.com/infoce...d/tjvjcerr.htm
try {
stmt.executeUpdate("CREATE TABLE t ( a INT )");
} catch (SQLException e) {
System.out.println("SQL Exception");
System.out.println("=============");
System.out.println(e.getMessage()); // (1)
System.out.println("");
if (e instanceof DB2Diagnosable) {
DB2Diagnosable db2e = (DB2Diagnosable)e;
DB2Sqlca sqlca = db2e.getSqlca();
System.out.println(sqlca.getMessage()); // (2)
}
}
You will see in step (1) the error message that contains the sqlcode,
sqlstate, and tokens - which you posted above. On step (2) you will
receive the short message for the error. Or do you need the long error
message, which includes Explanation and User Response, i.e. exactly what
this would return:
$ db2 "? sql0601"
Here is an example of the output I got:
$ javac A.java && java A
SQL Exception
=============
DB2 SQL error: SQLCODE: -601, SQLSTATE: 42710, SQLERRMC: STOLZE.T;TABLE
The name of the object to be created is identical to the existing
name "STOLZE.T" of type "TABLE".
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany