Skip to content
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

SqlTimeoutException expected: Got SQLServerException #634

Closed
eivinhb opened this issue Feb 23, 2018 · 5 comments
Closed

SqlTimeoutException expected: Got SQLServerException #634

eivinhb opened this issue Feb 23, 2018 · 5 comments
Labels
Bug A bug in the driver. A high priority item that one can expect to be addressed quickly.
Projects

Comments

@eivinhb
Copy link

eivinhb commented Feb 23, 2018

Driver version or jar name

6.2.2.jre8

SQL Server version

SQL Server 2014 (Not important)

Client operating system

MacOS

Java/JVM version

1.8.0_121 (Not important)

Table schema

NA

Problem description

The java Statement-interface says:

@throws SQLTimeoutException when the driver has determined that the
* timeout value that was specified by the {@code setQueryTimeout}
* method has been exceeded and has at least attempted to cancel
* the currently running {@code Statement}
ResultSet executeQuery(String sql) throws SQLException;

But mssql-jdbc throws a com.microsoft.sqlserver.jdbc.SQLServerException: The query has timed out. instead. I think this is an old issue, since the non open source version also has this incorrect implementation of the api. I have looked at the code, and it is a tiny bit complicated to find a solution since the IOBuffer that is now throwing this exception has no idea for the cause, it only knows that the command is interrupted.

I understand that this i an API change for the driver. But catching an exception and reading the text in the message to find out if we have a timing issue is is not a good practice.

Expected behavior and actual behavior

Should do what the java API has as a documented behaviour and throw a java.sql.SQLTimeoutException when statement setQueryTimeout is set.

Repro code

I was inspired by #525 and made this:

public static void main(String[] args) throws Exception {
        DriverManager.class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

        Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost;databaseName=mydatabase", "sa", "Password"
        Statement statement = connection.createStatement();
        statement.setQueryTimeout(1);

        try {
            statement.execute("WAITFOR DELAY '00:00:2'; SELECT 1");
        } catch (java.sql.SQLTimeoutException e) {
            System.out.println("Jey!");
        } catch (java.sql.SQLException e) {
            System.err.println("This is not the exception you are looking for: " + e.toString());
        }
} 
@cheenamalhotra cheenamalhotra added this to Under Investigation in MSSQL JDBC Feb 23, 2018
@ulvii
Copy link
Contributor

ulvii commented Feb 26, 2018

Hi @eivinhb ,

Thank you for creating the issue, it is indeed a deficiency in the driver. We will address the issue in one of the upcoming preview releases.

@ulvii ulvii added the Bug A bug in the driver. A high priority item that one can expect to be addressed quickly. label Feb 26, 2018
@cheenamalhotra cheenamalhotra moved this from Under Investigation to In progress in MSSQL JDBC Feb 28, 2018
@rene-ye
Copy link
Member

rene-ye commented Mar 6, 2018

Hello @eivinhb, we recently created PR #641 with a fix to this issue. Please feel free to take a look, and see if it has resolved any problems you were encountering.

@cheenamalhotra cheenamalhotra moved this from In progress to Waiting for Customer in MSSQL JDBC Mar 9, 2018
@eivinhb
Copy link
Author

eivinhb commented Mar 22, 2018

Looking av the code it seems to work fine. As a note, I would be scared to use string-equals check to identify the cause. Where the string originates from there is a //TODO where localisation is wanted to be added. So if the message is changed, the functionality also brakes. But this is not for me to address.

Anyway, I am now not able to compile the dev-branch with java 8 since the classes, like ISQLServerConnection43.java, uses java.sql.ShardingKey. I think the exclusion added in the build42-profile does not work since the class is in use in SQLServerDataSource.java so the compiler plugin will try and compile the class anyway.

@rene-ye
Copy link
Member

rene-ye commented Mar 22, 2018

Hi @eivinhb, the driver needs to be compiled with Java 9. You can compile a Java 8 jar by adding -Pbuild42 to your maven build commands, but Java 9 will still be used for the compilation. E.g. mvn clean install -Pbuild42

As for the localization issues, the string we use is an error message that gets localized in other languages of the driver, so there shouldn't be any problems as long as the resources are changed.

@peterbae
Copy link
Contributor

Fixed in PR #641.

MSSQL JDBC automation moved this from Waiting for Customer to Closed Issues Mar 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in the driver. A high priority item that one can expect to be addressed quickly.
Projects
MSSQL JDBC
  
Closed Issues
Development

No branches or pull requests

4 participants