PreparedStatement batch exception: missing trigger message
See original GitHub issueDriver 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™ SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot™ 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)
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Batch Inserts Using JDBC Prepared Statements - Vertica
Triggers an exception if used when streaming batch inserts are enabled. Notes. Using the PreparedStatement.setFloat() method can cause rounding errors. If ...
Read more >ORA-00928: missing SELECT keyword. when inserting record ...
The problem was caused by the number column name since number is a reserved keyword in Oracle, and the exception was sort of...
Read more >SQL error messages and exceptions - Oracle Help Center
System generated stored prepared statement ' <statement> ' that cannot be dropped using DROP STATEMENT. It is part of a trigger. 42Y83, An...
Read more >How to fix java.sql.SQLException: Invalid column index ...
here is a sample code example of getting some data from the PreparedStatement SELECT SQL query. here we have put just one placeholder...
Read more >Spring Batch - Reference Documentation
Message -driven applications are driven by messages retrieved from a message ... In other words, the eleventh skip triggers the exception, not the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I tested and approved the fix, thanks @v-afrafi . Feel free to use the test case.
I think I worked out something near to a reproducer. First, I run this:
Then this:
Then I run this class: https://gist.github.com/NicolaIsotta/792c47791511dd918ebc74ebcc576c42 The result is:
As you can see, the PreparedStatement exception does not contain the custom trigger message.