5 messages in com.mysql.lists.javaSQLException: "Cannot convert value.....| From | Sent On | Attachments |
|---|---|---|
| Michael McTernan | 20 Sep 2004 08:30 | |
| Jeff Mathis | 20 Sep 2004 08:41 | |
| Michael McTernan | 20 Sep 2004 08:53 | |
| Javier Ponce Albendea | 20 Sep 2004 09:16 | |
| Michael McTernan | 20 Sep 2004 09:30 |
| Subject: | SQLException: "Cannot convert value..." from getDate()![]() |
|---|---|
| From: | Michael McTernan (Mich...@ttpcom.com) |
| Date: | 09/20/2004 08:30:56 AM |
| List: | com.mysql.lists.java |
Hi there,
I'm using the mysql-connector version 3.0.15-ga, and server 4.1.4-gamma-standard-log. I'm finding that I can't retrieve TIMESTAMP columns, and get the following exception:
Exception in thread "main" java.sql.SQLException: Cannot convert value '2004-09-20 00:00:00' from column 1(2004-09-20 00:00:00 ) to DATE. at com.mysql.jdbc.ResultSet.getDate(ResultSet.java:1036) at com.mysql.jdbc.ResultSet.getDate(ResultSet.java:905) at com.mysql.jdbc.ResultSet.getDate(ResultSet.java:919) at DateTest.main(DateTest.java:36)
I've made a simple standalone class that shows this behavoiour, the main function of which is as follows:
public static void main(String args[]) throws Exception { Connection dbConn = getConnection(); PreparedStatement dbQuery; ResultSet dbResult;
/* Create table */ dbQuery = dbConn.prepareStatement( "CREATE TABLE test ( val TIMESTAMP )"); dbQuery.executeUpdate(); dbQuery.close();
/* Insert value */ dbQuery = dbConn.prepareStatement( "INSERT INTO test(val) VALUES(?)"); dbQuery.setDate(1, new Date(System.currentTimeMillis())); dbQuery.executeUpdate(); dbQuery.close();
/* Select value */ dbQuery = dbConn.prepareStatement( "SELECT val AS v FROM test"); dbResult = dbQuery.executeQuery();
if(dbResult.first()) { do { System.out.println(dbResult.getDate("v").toString()); } while(dbResult.next()); }
dbQuery.close(); dbConn.close(); }
If I try using the 3.1.4-beta connector, I find that the above test is okay and I get no exception and the expected output. I'd really like to not use the beta connector in a production environment though. I was wondering, are there plans to back port the fix to get the .15-ga connector to work with the 4.1.4-gamma server?
Thanks,
Mike
-- Michael McTernan Software TTPCom Ltd Melbourn Science Park, Cambridge Road, Melbourn, Hertfordshire, SG8 6HQ, UK T: +44 1763 266266 | F: +44 1763 261216 mich...@ttpcom.com | www.ttpcom.com




