Any way to get a column calling com.microsoft.sqlserver.jdbc.SQLServerException: string or binary data will be truncated

We have a webapp that uses hibernate to store data in an instance of sql server 2005.

Sometimes we get a com.microsoft.sqlserver.jdbc.SQLServerException: String or binary data would be truncated.

While we can get the insert request and then manually compare with the definition of the column in the database to see which column is too small, it is slow and error prone. Is there a way to automatically get a table / column that has a problem from this exception?

I searched Google and SO for a solution, so I understand if the answer is “no, you can’t get this information”, but I decided it wasn’t painful to ask.

+6
source share
1 answer

This error can occur when you try to put larger data in a table column than you can, for example:

your column parameter is varchar (10) and you are trying to put "some data is longer than 10"

Then you get an error, for example: com.microsoft.sqlserver.jdbc.SQLServerException: String or binary data would be truncated.

Check your input and your settings.

-2
source

All Articles