Loading a DLL file into an eclipse java project

I am trying to add the sqljdbc_auth.dll file to the project library. I am adding the folder containing the dll to the outer class folder.

Here, I'm mostly trying to connect to my SQL SERVER 2008 database using SQL drivers provided by Microsoft.

My code

 private static void Connect(){ try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String connectionUrl = "jdbc:hostname:1433;databaseName=dbname;" + "user=username;password=password"; java.sql.Connection con = DriverManager.getConnection(connectionUrl); } catch(ClassNotFoundException e) { e.printStackTrace(); } catch(SQLException e2) { e2.printStackTrace(); } }` 

I get the following error

 WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId:b83147c7-b45a-4f35-b601-195a0aa9c32c at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667) at com.microsoft.sqlserver.jdbc.AuthenticationJNI.<init>(AuthenticationJNI.java:60) at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2229) at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41) at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220) at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696) at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at com.sagar.com.package1.T1.Connect(T1.java:21) at com.sagar.com.package1.T1.main(T1.java:37) Caused by: java.lang.UnsatisfiedLinkError: no sqljdbc_auth in java.library.path at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.loadLibrary0(Unknown Source) at java.lang.System.loadLibrary(Unknown Source) at com.microsoft.sqlserver.jdbc.AuthenticationJNI.<clinit>(AuthenticationJNI.java:35) ... 13 more 
+4
source share
3 answers

If you want to use the DLL from Eclipse, you need to include the DLL in a place on the PATH system, or you need to explicitly specify the java.library.path property in the Eclipse launch configuration.

+2
source

Another option is to add something similar to the VM parameters of the main project class:

 -Djava.library.path="C:\Program Files\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu\auth\x64" 

(indicating the path to the sqljdbc_auth.dll file). There is no need to change the PATH or Eclipse IDE settings.

For the main class of the project, select the menu item Run As >> Run Configurations... Run Configurations ...

+7
source

On Windows platforms, Java.library.path has a PATH environment variable by default. A simple solution is to copy the DLL to your path (e.g. windows / system32) and restart eclipse. Also, the type of DLL must correspond to the version of Java, i.e. If you are using 32-bit Java, then you should use the 32-bit DLL

+1
source

All Articles