Saturday, 1 September 2012

. What is SQLWarning and discuss the procedure of retrieving warnings?


• SQLWarning objects, a subclass of SQLException is responsible for the database access warnings.

• Warnings will not stop the execution of an specific application, as exceptions do.

• It simply alerts the user that something did not happen as planned. 

• A warning may be reported on the Connection object, the Statement object (including PreparedStatement and CallableStatement objects) or on the ResultSet object.

• Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object:

Code :
SQLWarning waring = 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.println("Vendor error code: ");
System.out.println(warning.getErrorCode());
System.out.println("");
warning = warning.getNextWarning();
}
}

No comments:

Post a Comment