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.


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

I'm a Full stack developer of IT exp in J2EE, AngularJs, MicroServices, Docker, Spring (Boot, MVC, Cloud), Bluemix, DevOps. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.

%d bloggers like this: