File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
JDBC and Relational Databases
truncation errors storing a Date in MySQL table
Joined: Sep 01, 2009
Oct 01, 2009 04:26:15
I have a 'timestamp' field in a mysql table.
when I attempt to insert a Date into the table. Like this:
Date currentTime = new Date(new java.util.Date().getTime()); queryString = "INSERT INTO example_table (timestamp) VALUES ('" + currentTime + "')" connection.exectuteUpdate(queryString )
I get the error: Data truncation: Incorrect datetime value: 'Thu Oct 01 11:08:57 BST 2009'
I've tried changing the timestamp field to DATETIME, TIMESTAMP and DATE but to no avail.
What am I doing wrong?
Joined: Dec 20, 2006
Oct 01, 2009 14:18:15
and set the time with setDateTime();
If you would print your sql statement before executing it, you would see why it fails. The value of currenTime is not what you expect.
OCUP UML fundamental and ITIL foundation
I agree. Here's the link:
subject: truncation errors storing a Date in MySQL table
gps week/seconds conversion
MySQL - Date/Time and Timestamp Issues
MySQL DATE_FORMAT for INSERT
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015