EasyManua.ls Logo

IBM DB2

IBM DB2
585 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
EzSqljNameIter iter;
int count=0;
#sql [ctx] iter =
{SELECT LASTNAME FROM EMPLOYEE}; 4b
// Create result table of the SELECT
while (iter.next()) { 4c
System.out.println(iter.LASTNAME());
// Retrieve rows from result table
count++;
}
System.out.println("Retrieved " + count + " rows of data");
}
catch( SQLException e ) 5
{
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);
e.printStackTrace();
}
try
{
#sql [ctx] 4d
{UPDATE DEPARTMENT SET MGRNO=:hvmgr
WHERE DEPTNO=:hvdeptno}; // Update data for one department
6
#sql [ctx] {COMMIT}; // Commit the update
}
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);
e.printStackTrace();
}
iter.close(); // Close the iterator
ctx.close(); 7
}
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();
}
}
102 Application Programming Guide and Reference for Java

Table of Contents