File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes truncation errors storing a Date in MySQL table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "truncation errors storing a Date in MySQL table" Watch "truncation errors storing a Date in MySQL table" New topic
Author

truncation errors storing a Date in MySQL table

mat buckland
Greenhorn

Joined: Sep 01, 2009
Posts: 24
I have a 'timestamp' field in a mysql table.

when I attempt to insert a Date into the table. Like this:


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?

thanks
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2476
    
    7

Use a java.sql.PreparedStatement 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.

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: truncation errors storing a Date in MySQL table
 
Similar Threads
MySQL - Date/Time and Timestamp Issues
Timestamp assistance
Date/Timestamp
MySQL DATE_FORMAT for INSERT
gps week/seconds conversion