File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes MySQL DATE_FORMAT for INSERT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: MySQL DATE_FORMAT for INSERT
 
Similar Threads
MysqlDataTruncation
java.sql.sqlexception data size bigger than max size for this type
datefiled in dd-mm-yyyy format
Unable to materialize as string ERROR
SQL Show Previous Month Date Question