Bug #1356 unable to cast date field as Java date type
Submitted: 19 Sep 2003 17:07 Modified: 19 Sep 2003 17:21
Reporter: Patrick Dobbs Email Updates:
Status: Closed Impact on me:
Category:MySQL Server Severity:S2 (Serious)
Version:4.10 alpha OS:Windows (W2K)
Assigned to: CPU Architecture:Any

[19 Sep 2003 17:07] Patrick Dobbs
Using JDBC driver mm.mysql.2.0.4-bin.jar with Tomcat 4.1.27. We have a select query which returns a recordset including a field with type "datetime", format.

This recordset is then mapped to objects, where the Java type mapping to the datetime field is "date". We use the following code:

timestamp = (Date)rst.getObject(TIMESTAMP) 

With MySQL 4.1.0 alpha this results in java.lang.ClassCastException.

Installing MySQL 4.0 fixes the problem.

How to repeat:
1) Get a JDBC recordset returning a field of type "datetime".
2) Try to cast this value as a Java date type like this: (Date)rst.getObject()

Suggested fix:
Uninstall MySQL 4.1.0 alpha and revert to 4.0
[19 Sep 2003 17:21] Mark Matthews
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at

You need to use Connector/J 3.1.x with MySQL-4.1.x to make sure everything works correctly (as protocol-level stuff has changed in MySQL-4.1).

See http://mmmysql.sourceforge.net/snapshots/stable/ for the latest nightly build which shouldn't have this problem.