4

I am trying to add the file sqljdbc_auth.dll to the project library. I add the folder containing the dll as external class folder.

Here I am basically trying to connect to my SQL SERVER 2008 database using SQL drivers given by Microsoft.

My code is

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
user544079
  • 16,109
  • 42
  • 115
  • 171
  • Are you sure there is only a .dll library for it, no .jar? – NoBugs Jan 23 '13 at 01:45
  • I have already added the 2 external jar files i.e. sqljdbc and sqljdbc4 – user544079 Jan 23 '13 at 01:48
  • Are the .dll and the jvm the same bit type (32bit/64bit)? – NoBugs Jan 23 '13 at 02:00
  • 1
    What version of the Microsoft JDBC driver are you using? You ***should*** be using the Type 4 drivers, which do not require any platform dependent (DLL) libraries to be loaded. Better yet, use [JTDS](http://jtds.sourceforge.net/). – Perception Jan 23 '13 at 03:06
  • @Perception If you want to use Integrated Security (which uses your windows/active directory credentials to authenticate) then you need the dll, if you don't want to use Integrated Security, you don't need the dll. – Mark Rotteveel Jan 23 '13 at 09:04
  • @user544079 If you use Java 6 or higher, you should only use `sqljdbc4.jar` (and not include the `sqljdbc.jar`) – Mark Rotteveel Jan 23 '13 at 09:05
  • @MarkRotteveel - he's not using integrated security. Not currently anyway - check out his JDBC URL. – Perception Jan 23 '13 at 09:11
  • @Perception The url in the question isn't valid anyway, so I just assumed it was anonimysed a bit too much. If you check the stacktrace it is actually using integrated security; I am not sure how the driver behaves when the server only allows integrated security – Mark Rotteveel Jan 23 '13 at 09:13
  • @NoBugs: yes, the sqljdbc_auth.dll is for x64 as it is a 64 bit PC.@Perception: I am using the Type 4 driver from Microsoft JDBC. – user544079 Jan 24 '13 at 16:01

3 Answers3

9

Another option is to add something like this to the VM parameters of the project's main class:

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

(specifying the path to the sqljdbc_auth.dll file). There's no need to change the environment PATH or Eclipse IDE jvm parameters.

For the project's main class, select menu option Run As >> Run Configurations... Run Configurations...

brasofilo
  • 25,496
  • 15
  • 91
  • 179
Jose Tepedino
  • 1,524
  • 15
  • 18
2

If you want to use a DLL from inside Eclipse, you either need to include the DLL in a location on the system PATH, or you need to explicitly specify the java.library.path property in the run configuration of Eclipse.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
1

On windows platforms the Java.library.path defaults to the PATH environment variable. The simple solution is to copy the DLL into your path (e.g. windows/system32) and restart eclipse. Also the DLL type must match the Java version ie if you're using 32bit Java then you should use the 32bit DLL