Search code examples
javasql-serverjdbcmssql-jdbc

Jar not getting executed in other's pc [problem with JDBC external jar/maven dependency, connection not getting established]


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.


Solution

  • 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)