This week's book giveaway is in the Spring forum.
We're giving away four copies of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 and have Marten Deinum & Iuliana Cosmina on-line!
See this thread for details.
Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

MySQL DATE_FORMAT for INSERT

 
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic