File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MySQL DATE_FORMAT for INSERT

 
Timothy Sam
Ranch Hand
Posts: 751
  • 0
  • 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
  • 0
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic