Cjxcz Odjcayrwl
Cjxcz Odjcayrwl

Reputation: 22867

IBM DB2 JDBC over ODBC: SQLException thrown when running delete on empty table

I'm accessing IBM DB2 datatable available as ODBC datasource, using sun.jdbc.odbc.JdbcOdbcDriver driver.

The problem that I've encountered is, when I'm executing DELETE FROM table using java.sql.Statement.executeUpdate(String), and the table is empty, the java.sql.SQLException is thrown (the expected behaviour is that 0 should be returned). The exception message is "No data found".

It's my first contact with IBM DB2, so my question is, is that expected behaviour on that database? Or this is something that can be configured on database level? Or it is ODBC-specific thing?

If it is standard behaviour, how should I recognize that 'exception' from real exceptions? I don't like parsing exception messages for business logic, but if it is necessary, can I expect, it will always be "No data found"?

I've tried to google the specification of that behaviour, but I've found no documentation for that case.

Upvotes: 2

Views: 377

Answers (1)

AngocA
AngocA

Reputation: 7693

This is completely normal. DB2 did not found anything to delete, and return this warning.

Many databases have the same status: sqlstate 02000. Take a look in Google and you will see that other RDBM have the same code. However, DB2 has sqlcode to explain the reason, and for this sqlstate, the corresponding code is sql0100W.

You have to deal with this behaviour while working with DB2, this is a SQLWarning (The W at the end of the sqlcode).

http://publib.boulder.ibm.com/infocenter/db2luw/v10r1/topic/com.ibm.db2.luw.messages.sql.doc/doc/msql00100w.html

For the next time, take a look at the sqlcode. It will help you to find the problem while working with DB2.

Upvotes: 2

Related Questions