3
votes

I have multiple applications that needs to connect to MSSQL using windows authentication.

The First webApp which is loaded works fine. but the remaining fail prompting

Caused by: java.lang.UnsatisfiedLinkError: Native Library $tomcat/bin/sqljdbc_auth.dll already loaded in another classloader

Below is the code used

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
connection= DriverManager.getConnection("jdbc:sqlserver://localhost;databaseName=XXX;integratedSecurity=true");

I Have placed sqljdbc*.jar --> tomcat*/lib and sqljdbc_auth.dll --> tomcat*/bin

Seems like all my applications are trying to load the shared lib($tomcat/bin/dll) multiple times. Hence the first load works and the remaining fail.

Edit: I understand that the native library (DLL) can only be loaded into the JVM once, hence the error, but I after looking around the net I still have no solution.

How can i load the dll only once?

Please Help!!

1
as mentioned i have already placed the files to the particular folders. But still the same error. - divya krishna

1 Answers

0
votes

I would guess. That removing the line

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

would solve the problem.

As mentioned in the javadoc of DriverManager

The DriverManager methods getConnection and getDrivers have been enhanced to support the Java Standard Edition Service Provider mechanism.
...
Applications no longer need to explictly load JDBC drivers using Class.forName().

edit This requires a jdbc driver which supports the JDBC 4.0 API. Which should be the case from Microsoft JDBC driver 4.0 on (see: https://docs.microsoft.com/en-us/sql/connect/jdbc/system-requirements-for-the-jdbc-driver)

A matrix which Microsoft JDBC driver supports which SQL server version you can find at https://docs.microsoft.com/en-us/sql/connect/jdbc/microsoft-jdbc-driver-for-sql-server-support-matrix