Note that there are some explanatory texts on larger screens.

plurals
  1. POhandling DATETIME values 0000-00-00 00:00:00 in JDBC
    text
    copied!<p>I get an exception (see below) if I try to do </p> <pre><code>resultset.getString("add_date"); </code></pre> <p>for a JDBC connection to a MySQL database containing a DATETIME value of 0000-00-00 00:00:00 (the quasi-null value for DATETIME), even though I'm just trying to get the value as string, not as an object.</p> <p>I got around this by doing </p> <pre><code>SELECT CAST(add_date AS CHAR) as add_date </code></pre> <p>which works, but seems silly... is there a better way to do this?</p> <p>My point is that I just want the raw DATETIME string, so I can parse it myself <strong>as is</strong>.</p> <p><strong>note:</strong> here's where the 0000 comes in: (from <a href="http://dev.mysql.com/doc/refman/5.0/en/datetime.html" rel="noreferrer">http://dev.mysql.com/doc/refman/5.0/en/datetime.html</a>)</p> <blockquote> <p>Illegal DATETIME, DATE, or TIMESTAMP values are converted to the “zero” value of the appropriate type ('0000-00-00 00:00:00' or '0000-00-00').</p> </blockquote> <p>The specific exception is this one:</p> <pre><code>SQLException: Cannot convert value '0000-00-00 00:00:00' from column 5 to TIMESTAMP. SQLState: S1009 VendorError: 0 java.sql.SQLException: Cannot convert value '0000-00-00 00:00:00' from column 5 to TIMESTAMP. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926) at com.mysql.jdbc.ResultSetImpl.getTimestampFromString(ResultSetImpl.java:6343) at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5670) at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5491) at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5531) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload