java.sql.DataTruncation: Data truncation problem handling

java.sql.DataTruncation: Data truncation
	at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:382)
	at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2820)
	at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2258)
	at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:632)
	at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)

    When you look at this error message, you know that the data content is too long, and the length given by the database column is not enough. I know the reason, but it took me about three hours to investigate this problem. It was a lot of tracking and debugging, and all the content was removed, leaving only an ID primary key. Direct insertion still prompted this error, which was really confusing. . Finally, I put the incoming and outgoing statements on the sql server client to execute, and the error reported finally made me realize.

Msg 8115, Level 16, State 2, Line 1
An arithmetic overflow error occurred while converting expression to data type datetime.
Statement terminated.

 It means that the conversion date is wrong, but I did not assign a value to this type of field. I thought that SQL Server has a default value, and finally removing that default value solved the problem.

 

     Lesson: When sqlserver creates fields, pay attention to the default value settings, especially for date and time types.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326931033&siteId=291194637