This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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: 2543
    
  10

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
 
Have you checked out Aspose?
 
subject: truncation errors storing a Date in MySQL table
 
It's not a secret anymore!