SQL/MX Programming Manual for Java

SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java523726-003
3-64
Chained Exceptions and Warnings
} // end of main() method
} // end class SQLWarningExample
SQL Warnings in an Implicit Execution Context
This example is the same as the previous one, except that it calls getWarnings() by
using an implicit execution context:
import java.sql.*;
import sqlj.runtime.*;
public class SQLWarningExample {
public SQLWarningExample() {
}
public static void main (String [] args) {
SQLWarning warn;
Float floatQty = new Float(37.5);
try {
// Set an exact numeric column to a floating-point value,
// resulting in a truncation warning at run time
#sql { UPDATE samdbcat.invent.partloc
SET qty_on_hand = :floatQty
WHERE loc_code = G76
AND partnum = 7301 };
// Handles SQL warnings from the UPDATE statement
warn = DefaultContext.getDefaultContext().
getExecutionContext().getWarnings();
if (warn != null) {
System.out.println("Warning: " + warn);
}
} // End of try block
// Handles SQL exceptions from the try block
catch (SQLException se) {
System.err.println("SQL exception: " + se);
}
} // end of main() method
} // end class SQLWarningExample
Chained Exceptions and Warnings
When multiple SQL errors occur, they are chained together in an SQLException
object. Each SQLException object has a getNextException() method that
returns the next exception in the chain. The setNextException() method accepts
an SQL exception and adds it to the end of the chain.
When multiple SQL warnings occur, they are chained together in an SQLWarning
object. Each SQLWarning object has a getNextWarning() method that returns the