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?
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.
This, 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.