0

I am trying to insert a set of values to a table in SQL Server Database. The table contains 600 columns. The exception while inserting value is as follows. We are using ibatis as the tool for DB transactions.

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: String or binary data would be truncated.
 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:217)
 at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1651)
 at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:446)
 at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:383)
 at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7465)
 at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2271)
 at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:191)
 at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:166)
 at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:365)
 at weblogic.jdbc.wrapper.PreparedStatement.execute(PreparedStatement.java:94)
 at sun.reflect.GeneratedMethodAccessor186.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.invoke(PreparedStatementLogProxy.java:62)
 at com.sun.proxy.$Proxy197.execute(Unknown Source)
 at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:81)
 at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteUpdate(GeneralStatement.java:200)
 at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:78)

In Oracle, it would have shown which value is too large for the column . In SQL Server is there any way to find out which value is causing this issue? Thanks in advance!

TT.
  • 15,428
  • 6
  • 44
  • 84
  • 1
    Possible duplicate of [How to figure out which string or binary data would be truncated?](http://stackoverflow.com/questions/29513665/how-to-figure-out-which-string-or-binary-data-would-be-truncated) – ahmed abdelqader Dec 01 '16 at 13:36
  • Looks like a duplicate to me too, going to flag it. – Neo Dec 01 '16 at 13:39
  • 1
    Guys, question might be repetitive but the scenario is different. Here we are sending dynamic data through ibatis !. Please suggest us to find out which data is causing the problem ! – Jathin Sreenivas Dec 01 '16 at 13:42
  • 1
    SQL Server does not report which value would be truncated, so that leaves you with analyzing the length of the data you pass on to SQL Server. I don't know ibatis so I can't comment on that, but I doubt ibatis will tell you either. You need to be aware of the maximum length of `(N)VARCHAR` columns and make sure you don't pass data that is wider. Either work in that maximum length in your presentation layer, and/or in your mapping layer to truncate values that are too wide or have your mapping layer error when passed values are too wide. – TT. Dec 01 '16 at 14:33

0 Answers0