This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MySQL DATE_FORMAT for INSERT

 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, I'm always getting a Data Truncation error in MySQL


com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect datetime value: '03/02/1996'



Would it be possible to use MySQL DATE_FORMAT() function to format the String and INSERT a record like this:

[code
INSERT INTO education_tbl(highschool, highschool_date_graduated, college, college_date_graduated, course) VALUES(?, DATE_FORMAT(?, '%m-%d-%y'), ?, DATE_FORMAT(?, '%m-%d-%y'), ?)
[/code]


I'm still getting the error after I did that... Thanks!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best thing to do is use a PreparedStatement and bind the Date variable, then you don't need to care about the format or use any database funtions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic