IBM DB2 Manual page 118

Table of Contents

Advertisement

}
102
Application Programming Guide and Reference for Java
EzSqljNameIter iter;
int count=0;
#sql [ctx] iter =
{SELECT LASTNAME FROM EMPLOYEE};
while (iter.next()) {
System.out.println(iter.LASTNAME());
count++;
}
System.out.println("Retrieved " + count + " rows of data");
}
catch( SQLException e )
{
System.out.println ("**** SELECT SQLException...");
while(e!=null) {
System.out.println ("Error msg: " + e.getMessage());
System.out.println ("SQLSTATE: " + e.getSQLState());
System.out.println ("Error code: " + e.getErrorCode());
e = e.getNextException(); // Check for chained exceptions
}
}
catch( Exception e )
{
System.out.println("**** NON-SQL exception
e.printStackTrace();
}
try
{
#sql [ctx]
{UPDATE DEPARTMENT SET MGRNO=:hvmgr
WHERE DEPTNO=:hvdeptno};
#sql [ctx] {COMMIT};
}
catch( SQLException e )
{
System.out.println ("**** UPDATE SQLException...");
System.out.println ("Error msg: " + e.getMessage() + ". SQLSTATE=" +
e.getSQLState() + " Error code=" + e.getErrorCode());
e.printStackTrace();
}
catch( Exception e )
{
System.out.println("**** NON-SQL exception
e.printStackTrace();
}
iter.close();
ctx.close();
}
catch(SQLException e)
{
System.out.println ("**** SQLException ...");
System.out.println ("Error msg: " + e.getMessage() + ". SQLSTATE=" +
e.getSQLState() + " Error code=" + e.getErrorCode());
e.printStackTrace();
}
catch(Exception e)
{
System.out.println ("**** NON-SQL exception = " + e);
e.printStackTrace();
}
// Create result table of the SELECT
// Retrieve rows from result table
// Update data for one department
// Commit the update
// Close the iterator
4b
4c
5
= " + e);
4d
6
= " + e);
7

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents