Pages Navigation Menu

Coding is much easier than you think

How to retrieve SQLWarning in java?

Posted by on Aug 21, 2013 in JDBC | 0 comments

SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warning simply alerts the user when something did not happen as planned. A warning can be reported on a Connection, ResultSet and Statement object. Each of these classes has a getWarnings() method, which we must invoke in order to see the warning reported on the calling object.


SQLWarning statementWarning = statement.getWarnings();

	while (statementWarning != null) 
		System.out.println("Error code: " + statementWarning.getErrorCode());
		System.out.println("SQL State: " + statementWarning.getSQLState());
		System.out.println("Warning Message: " + statementWarning.getMessage());
		statementWarning = statementWarning.getNextWarning();


Note: clearWarning() method is used to clear all the warning reported by the call of Connection, ResultSet, and Statement objects.


Read More