aspose file tools
The moose likes JDBC and the fly likes MySQL DATE_FORMAT for INSERT Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "MySQL DATE_FORMAT for INSERT" Watch "MySQL DATE_FORMAT for INSERT" New topic
Author

MySQL DATE_FORMAT for INSERT

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
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!


SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: MySQL DATE_FORMAT for INSERT
 
Similar Threads
Unable to materialize as string ERROR
MysqlDataTruncation
SQL Show Previous Month Date Question
java.sql.sqlexception data size bigger than max size for this type
datefiled in dd-mm-yyyy format