• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

SQL warnings driving me nuts

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.io.*;
import java.util.*;
import java.sql.*;
class PELoad {
static {
try {
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
} catch (Exception e) {
System.out.println(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) {
System.out.println("\n---Warning---\n");
while (warning != null) {
System.out.println("Message: " + warning.getMessage());
System.out.println("SQLState: " + warning.getSQLState());
System.out.print("Vendor error code: ");
System.out.println(warning.getErrorCode());
System.out.println("");
warning = warning.getNextWarning();
} //while
} //main
con.close();
} catch(Exception e) {System.out.println(e);}
} //main
} //PEload
compiles fine...java program...computer starts thinking...sbam! nothing happens, not even a little error message. Any idea what I'm doing wrong?
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic