0

I have given date type and timestamp data type (4/2/2015 3:10:36 PM) also but I am getting below error. This date I am calling from XLSX sheet.

Exception in thread "main" com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '4/2/2015 3:10:36 PM' for column 'date' at row 1
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4235)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2825)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2156)
    at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379)
    at com.tasc.xls.SearchExcel.main(SearchExcel.java:64)
2
  • 5
    Show us your Java code. Commented Apr 3, 2015 at 4:21
  • Are you using a PreparedStatement with a placeholder? You should be doing something like statement.setDate(1, dateObj);. If you set it as a string (looks like you are and not parsing it), it's not going to work. Commented Apr 8, 2015 at 20:06

1 Answer 1

2

You are probably passing the date as a string in your prepared statement instead of passing it as a Date type. Passing it as a date type will send correctly your date to mysql.

Example:

PreparedStatement pstmt = con.prepareStatement("UPDATE my_table set my_date = ?");
pstmt.setDate(1, yourDateConvertedIntoDateType);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.