Home:ALL Converter>PreparedStatements should throw Exception instead of warning

PreparedStatements should throw Exception instead of warning

Ask Time:2015-02-02T22:49:06         Author:Vojtěch

Json Formatter

I am using PreparedStatements to write to database and sometimes I see following in my logs:

 2015-02-02 15:44:14,601  WARN SQL Warning Code: 1292, SQLState: 22007
 2015-02-02 15:44:14,602  WARN Incorrect datetime value: '2011' for column 'time_end' at row 1

However this is completely useless as I cannot see where in the code the problem is. Is it possible to force Connection/PreparedStatements to throw exceptions instead of these warnings?

Author:Vojtěch,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28280321/preparedstatements-should-throw-exception-instead-of-warning
dcsohl :

This isn't much help, but you can retrieve the warnings by a call to Connection.getWarnings() or PreparedStatement.getWarnings() or ResultSet.getWarnings() and examine the warning object there. These methods all return an SQLWarning object, which is the first in a chain; call warning.getNextWarning() to see subsequent messages.\n\nThis, of course, means you'll have to alter all your DB code to track down the problems; sorry I don't have a better option right now. If there is a way to force the JDBC code to throw these as real catchable exceptions, it is probably driver-specific.",
2015-02-02T15:27:30
yy