Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

truncation errors storing a Date in MySQL table

 
mat buckland
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic