Pages Navigation Menu

Coding is much easier than you think

How to retrieve SQLWarning in java?

How to retrieve SQLWarning  in java?

 
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.

E.g.

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.

 

About Mohaideen Jamil


Am currently working as a Struts 2 Developer in a reputed IT Organisations. I can help you with teaching Core java and Struts 2. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.