'Java. Lang. Runtimeexception: Driver Com. Microsoft. Sqlserver. Jdbc. Sqlserverdriver Claims to Not Accept jdbcUrl,'

'Java. Lang. Runtimeexception: Driver Com. Microsoft. Sqlserver. Jdbc. Sqlserverdriver Claims to Not Accept jdbcUrl,'

I am using below dependencies.

       <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
             <version>7.4.1.jre8</version>
        </dependency>

        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>adal4j</artifactId>
            <version>1.6.4</version>
        </dependency>

When I form the connection url like below.

  String connectionUrl = jdbcURL + ";databaseName=" + databaseName + ";user=" + userName + ";password="
                    + password
                    + ";encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;"
                    + "loginTimeout=30;authentication=ActiveDirectoryPassword";

I am getting error like:

' 'java.lang.RuntimeException: Driver com.microsoft.sqlserver.jdbc.SQLServerDriver claims to not accept jdbcUrl,'

When I enclosed the password in curly braces like below, I am able to successfully connect to Azure sql server.

String connectionUrl = jdbcURL + ";databaseName=" + databaseName + ";user=" + userName + ";password={"
                + password + "}"
                + ";encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;"
                + "loginTimeout=30;authentication=ActiveDirectoryPassword";

Just FYI, password has one open curly brace {, is it causing any trouble? is it mandatory to enclose the password string in curly braces?

2 Answers

This problem is resolved when I set the password using setPassword method.

dataSource.setPassword(password);

For me, I had to update the db.url from this:

jdbc:sqlserver:myservername.awsaddress.us-east-1.rds.amazonaws.com:1433;databaseName=exdb

to this:

jdbc:sqlserver://myservername.awsaddress.us-east-1.rds.amazonaws.com:1433;databaseName=exdb

I forgot the double forward slash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.