1

I have written a code to connect to a database using JDBC, I am using openJDK11.0.2, 64 bit, and external jar [mssql-jdbc-8.4.0.jre11] (which i added to libraries inside "properties" in eclipse)

I added a maven dependency as well

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>8.4.0.jre11</version>
</dependency>

So in my code, I am using windows authentication and my code looks like this,

public static void main(String[] args) throws SQLException {
        String connString = "jdbc:sqlserver://" + serverName + "\\MSSQLSERVER:1433;" + "databaseName = testUserDb; integratedSecurity = true;";
        System.out.print("\nConnection String : " + connString + "\n");
        conn = DriverManager.getConnection(connString);
        System.out.println("\nConnection Established");
        System.out.println("\nSuccess");
    }

I exported my code as a runnable jar, and the code is running fine when I am executing my jar using java -jar demoJava.jar

But when I gave my jar to my partner, on his computer (using same version of java) on his I got error, connection is not getting established.

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication

It there a way I can make my code universal, and it will run anywhere (when I am exporting as a runnable jar, the external mssqljdbc jar is present in my JAR) but it is only getting executed in my system.

What am I missing? Something to do with driver dlls? Please suggest.

horizon
  • 453
  • 2
  • 12

2 Answers2

1

Just add "mssql-jdbc_auth-8.4.0.x64.dll" to other peoples jdk_version/bin and rerun the process, it will work, I faced same problem. That is how I resolved it.

Make sure to use correct version (64/86)

SharadxDutta
  • 1,058
  • 8
  • 21
0

The very first Google result for this error message leads to documentation at Microsoft :

https://techcommunity.microsoft.com/t5/sql-server/com-microsoft-sqlserver-jdbc-sqlserverexception-this-driver-is/ba-p/383296

which says "This generally indicates that the driver can not find the appropriate sqljdbc_auth.dll in the JVM library path."

There's a fix recommend there for specifying the path to the DLL, assuming that you have it. Of course, that would only work on Windows.

A more universal approach would be to use a pure-java JDBC driver, like the jTDS JDBC Driver.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
  • So following the above approach is gonna make my JAR independent? – horizon Sep 23 '20 at 12:03
  • When I run the JAR in my PC, it is working fine, if I run the JAR on elses PC, will it run as it is or it will sitll need some other files? "I want to make my JAR independent once I ship it to other people" they will have to run the JAR and not worry about anything or placing a file. – horizon Sep 23 '20 at 12:05