Solve the error: ava.sql.BatchUpdateException: Data truncation: Incorrect datetime value: '1525-07-08 22:33:20'

This error is usually caused by a mismatch between the data value to be inserted and the data type defined by the database table structure. In this case, you can take the following steps to resolve the issue:

1. Check table structure and data types

Check that the table structure and data type are correct, and ensure that the data to be inserted matches the table structure and data type. If the data to be inserted exceeds the range defined by the table structure, a "Data truncation" error will occur.

 

2. Check the data format

Check that the data to be inserted is in the correct format. In this case, the error message states that the datetime value is invalid. Please ensure that the datetime value follows the correct format and the value is valid. For example, use a datetime value in the format "yyyy-mm-dd hh:mm:ss".

val sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

3. Use the correct character set

Check that the character set of the database table is set correctly, and make sure that the data to be inserted matches the character set of the table. Data truncation errors may occur if the character sets do not match.

4. Adjust the table structure

If none of the above resolve the issue, you may want to consider adjusting your table structure to accommodate larger datetime values. For example, changing the data type from DATETIME to TIMESTAMP or extending the field length to allow longer datetime values.

alter table <表名> modify column <列名> varchar(60);

Hope these suggestions help you solve your problem!

Guess you like

Origin blog.csdn.net/m0_58353740/article/details/130638799