File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes SQL warnings driving me nuts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL warnings driving me nuts" Watch "SQL warnings driving me nuts" New topic

SQL warnings driving me nuts

Sebastiano Barbieri

Joined: Jul 21, 2003
Posts: 5
Ok people. I'm using db2 and if I try to execute the statement:
Update t set i = 10 where i = 123
this row where i = 123 doesn't exist and I get the following warning: SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a
query is an empty table. SQLSTATE=02000
So far...everything's fine. Now I try to catch this warning through jdbc. Here's my code:
import java.util.*;
import java.sql.*;
class PELoad {
static {
try {
} catch (Exception e) {
} //catch
} //static
public static void main(String args[]) {
try {
Connection con = DriverManager.getConnection("jdbc b2 ELoad");
Statement stmt = con.createStatement();
stmt.executeUpdate("Update t set i = 10 where i = 123");
SQLWarning warning = stmt.getWarnings();
if (warning != null) {
while (warning != null) {
System.out.println("Message: " + warning.getMessage());
System.out.println("SQLState: " + warning.getSQLState());
System.out.print("Vendor error code: ");
warning = warning.getNextWarning();
} //while
} //main
} catch(Exception e) {System.out.println(e);}
} //main
} //PEload
compiles starts thinking...sbam! nothing happens, not even a little error message. Any idea what I'm doing wrong?
Paulo Salgado
Ranch Hand

Joined: Jan 18, 2002
Posts: 98
Not sure if you are testing the Warning thing or if you want to check whether the row was really updated. In the latter case, Statement.executeUpdate(...) should return an int, in your case it should be zero and you could go from there.
I agree. Here's the link:
subject: SQL warnings driving me nuts
It's not a secret anymore!