-
Notifications
You must be signed in to change notification settings - Fork 465
PreparedStatement batch exception: missing trigger message #457
Copy link
Copy link
Closed
Description
Driver version or jar name
6.2.1.jre7
SQL Server version
Microsoft SQL Server
13.00.4001
Client operating system
Windows 10
Java/JVM version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
Problem description
The exception thrown when a batch update fails because of a trigger is different based on the Statement type.
If it's a normal Statement, the trigger message is correctly shown.
Instead, if it's a PreparedStatement, the exception doen't contain the trigger message, so the issue is hard to find. Calling getCause() or getNextException() doesn't help.
Repro code
https://gist.github.com/NicolaIsotta/f10f9162c9dc89f903adc0df4644e662
The result of running the code is:
java.sql.BatchUpdateException: [Riga Insesistente] - Impossibile inserire, non esiste alcun legame tra la riga inserita e lariga dell'ordine acquisto!!
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeBatch(SQLServerStatement.java:1740)
at it.emmeduei.Test.testStatement(Test.java:40)
at it.emmeduei.Test.main(Test.java:67)
com.microsoft.sqlserver.jdbc.SQLServerException: Transazione terminata nel trigger. Il batch è stato interrotto.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:258)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1535)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.processResults(SQLServerStatement.java:1210)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.processBatch(SQLServerStatement.java:1201)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatementBatch(SQLServerPreparedStatement.java:2511)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtBatchExecCmd.doExecute(SQLServerPreparedStatement.java:2383)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7151)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2478)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:219)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:199)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeBatch(SQLServerPreparedStatement.java:2294)
at it.emmeduei.Test.testPreparedStatement(Test.java:58)
at it.emmeduei.Test.main(Test.java:68)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels