-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] PreparedStatement swallows exceptions from SQL batch #995
Comments
I have also reaised this issue on stackoverflow.com but have not received any replies. https://stackoverflow.com/questions/55226638/getting-exceptions-from-a-preparedstatement |
Hi @fhossfel, The reason why you are seeing this behavior is because the driver does not parse the result sets on |
This does not work. Since the INSERT Statement does not return a ResultSet calling getMoreResults() returns false. Hence I do not have a RequltSet from the failing statement to call getString(1) on. |
Please try:
|
This does not work. You will get the error message "Failed: Expected com.microsoft.sqlserver.jdbc.SQLServerException to be thrown, but nothing was thrown." from the unit test. |
I ran the test below and it seems to pass. Please make sure to update your project.
|
Thanks for the reply. I can run your unit successfully: The error is thrown. I I have analyzed this correctly you need to retrieve the complete ResultSet of the previous statment to get to the error. I think this is a bug nevertheless - or at least very surprsing. The JDBC spec says in section 14.1.4:
I admit, that this is in the section Batch Updates but I would argue that the general idea behind PreparedStatement/Statement is that they behave similar. As a matter of fact: I think that this is the whole idea behind inhertance in OOP. Currently the PreparedStatement has a lot of nasty surprises. I did not expect: a.) that the error is not thrown automatically upon exectuion I don't think there is any other JDBC driver that behaves that way. |
BTW: What do you do if you have a combination of one INSERT/UPDATE that runs and successfully and a second one that fails? Do you get an exception straight away? |
They do indeed behave the same in this scenario. Please try to debug both
In your scenario, the server returns the exception as a result set and there is not much the driver can do but let the application parse the result set.
I would again suggest to take a look at the issues #826, #937 for the detailed explanation about the current behavior.
I just confirmed that jTDS - another SQL Server JDBC driver behaves exactly the same. Please let me know if you have any other questions. |
No, that's not true. The statement test case throws the exception without having to call getString(1) on the result set. Does the SQL Server handle Statement and PreparedStatement differently or is this a difference in the driver?
Sorry, if I did not understand this correctly: Does this mean I get the data from two different statements in one ResultSet? I mean, does the server return one ResultSet which may have completely different meta data per row. I would have expected that I get two different ResultSets for two different SELECTs and that I use stmt.getMoreResults() to access them. IMHO the issues #826 and #937 are a strong indicator that I am not the only one who is, ummm, "surprised" by this behavior. I can confirm that Pentaho Data Integration is not usable with SQL Server. SO this problem seems to be fairly widespread. |
Hi @ulvii, sorry to bother you again but this is really quite a pressing issue for us. I have just adapter the unit test to use jTDS and it does not behave the same. It will throw and java.sql.SQLException without having to loop through the rows of a ResultSet or even getting the first row of the ResultSet. It is sufficient to call
pom.xml:
|
Hi @fhossfel , You are actually correct that PreparedStatement behaves differently and the difference seems to be introduced with this PR. Would you mind trying 6.4 version of the driver and let me know if it behaves the way you expect? In the meantime I will continue the investigations. |
Hi @ulvii, I can confirm that the unit test runs successfully with 6.4.0.jre8. I think I should be able to downgrade the driver to that version. Still, it would be nice if this could be addressed in a future release. Thanks Felix |
Driver version
7.2.1.jre8
SQL Server version
Microsoft SQL Server 2017 (RTM-CU13) (KB4466404) - 14.0.3048.4 (X64)
Nov 30 2018 12:57:58
Copyright (C) 2017 Microsoft Corporation
Express Edition (64-bit) on Linux (Ubuntu 16.04.5 LTS)
Client Operating System
Windows 10
JAVA/JVM version
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
Table schema
master
Problem description
Expected behaviour:
If I run a batch of SQL statements through PreparedStatement I expect any exception encountered to be thrown. This is what happens if you use a Statment
Actual behaviour:
No exeption is thrown.
Error message/stack trace:
Nothing!
Any other details that can be helpful:
This might be related to Throw the initial batchException #458
Reproduction code
pom.xml
SQLServerExceptionTest:
The text was updated successfully, but these errors were encountered: