How to get descriptive error messages from DB2?

When I call an SQL statement through JDBC in DB2 and the statement fails, I encounter a SQLException with the following message text:

com.ibm.db2.jcc.a.nn: DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703, SQLERRMC=O.METADATENSATZ, DRIVER=3.52.95 

I tried to automatically translate the message according to the list of errors published by IBM , but in messages that link to other elements of the exception.

When searching for these elements inside an exception, I found DB2ExceptionFormatter and tried to use it to access the missing elements.

But I stopped here because the DB2ExceptionFormatter gave me a hint:

An error occurred while trying to get the message text from the server. Only message tokens are available.

So my question is:. What do I need to configure to receive the correct messages from the DB2 server?

If I can receive a humanoid message from the server, I could use it directly and would not have to translate it myself.

+6
java db2 jdbc
source share
2 answers

I'm not sure which link to link you are looking at above (is this similar to iSeries?), But you better go to the link to DB2 by link.

Raising SQL0206, we get this page with the following information:

the name is not valid in the context in which it is used.

SQLERRMC is "O.METADATENSATZ", so I would say that you sent the SQL statement to DB2 and say that "O.METADATENSATZ" is invalid ... either the column does not exist, or the table "O" does not exist.

As the message link says, if you want to automatically translate DB2 error messages:

To display the help message, open a command line processor and enter:

? Xxxnnnnn

where XXX represents a valid message prefix and nnnnn is a valid message number.

The message text associated with this SQLSTATE value can be obtained by issuing:

? Nnnnn

or

? pp

where nnnnn is the five-digit SQLSTATE (alphanumeric), and nn is the two-digit SQLSTATE class code (the first two digits of the SQLSTATE value).

In your case, entering "? SQL0206" in the DB2 CLP will give you an error message.

+6
source share

I found a hint here :

retrieveMessagesFromServerOnGetMessage:

Indicates that JDBC calls SQLException.getMessage cause the IBM DB2 driver for JDBC and SQLJ to call the DB2 for z / OS stored procedure, which retrieves the message text for the error. The data type of this property is logical. The default value is false, which means that the full text of the message is not returned to the client.


I tried this, but the output of sqlException.getMessage() only changed to

 O.METADATENSATZ 

without surrounding message text.


Now I found this :

Before you can use certain features of the IBM® Data Server driver for JDBC and SQLJ in the DB2® subsystem for z / OS®, you need to install a set of stored procedures and create a set of tables.

...

WLM must be installed on z / OS.

WLM is the DB2 Workload Manager , which is not available for the release of DB2 Express, which I use for development: - (

+3
source share

All Articles