简体   繁体   中英

java.lang.UnsatisfiedLinkError: no sqljdbc_auth in java.library.path

I'm created a .jar of my java application, and when i'm try to run that .jar from cmd, i get an error.

I've been searching and found many examples, but no one work's for me. I set the java.library.path to the directory 'sqljdbc_auth.dll' like I saw here but the error continuous.

http://www.linglom.com/images/howto/netbeans/sqlserver/part3/8.png

I Run my java application with command : java -Djava.library.path= "my dll path" and give this:

PS C:\Users\User> java -Djava.library.path="C:\Users\User\Desktop\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc
_4.0\ptb\auth\x64"
Error: Could not find or load main class .library.path=C:\Users\User\Desktop\Microsoft JDBC Driver 4.0 for SQL Server
\sqljdbc_4.0\ptb\auth\x64

I really dont no how solve this. I've been searching a lot of time, but nothing works. Please someone help me.

THANKS

 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 integrat
ectionId:0481a2ee-4ac4-4fd3-89cd-58aad1696fe4
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.j
        at com.microsoft.sqlserver.jdbc.AuthenticationJNI.<init>(AuthenticationJNI.java:60)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.
        at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServe
        at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnect
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnecti
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.jav
        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 test.database.Conection.getConexao(Conection.java:41)
        at test.forms.jTLogin.<init>(jTLogin.java:71)
        at test.forms.jTLogin$4.run(jTLogin.java:448)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$400(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
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:3
        ... 28 more

Got it working...

1) Added .dll and .jar in Java/JDK/bin

2) Added .jar in applications/lib

3) Added .dll in windows/system32

add the java/jdk../bin and windows/system32 in "Path" system environment.

If you don't need "integrated security" you can just turn it off with parameter in url:

integratedSecurity=false;

This should be fine for development but probably also for some production environment.

After a full morning of frustration, I finally got it working, all I needed to do was part of @user3320956's first suggestion.

I added the sqljdbc_auth.dll to my JDK\bin directory (in my case C:\Program Files\Java\jdk1.7.0_79\bin) and the only thing in my CLASSPATH is

C:\Program Files\Microsoft JDBC Driver 4.1 for SQL Server\sqljdbc_4.1\enu\sqljdbc41.jar 

After that, as long as I didn't use the -cp or -classpath variables I was able to use this statement in my class:

import com.microsoft.sqlserver.jdbc.*;

and connect to a remote database. Here's my connection string (of course, replace SERVERNAME and DBNAME, make sure you have rights, make sure your server is setup to accept TCP/IP connections, etc.):

jdbc:sqlserver://SERVERNAME;database=DBNAME;integratedSecurity=true;authenticationScheme=NativeAuthentication;

HTH!

Cheers,

-Matthew

I was having same issue as OP, but I have not been able to resolve based on user3320956's response.

I'm using Intellij Idea, and I found that I was able to resolve this by changing the method from which I created the .jar. The "extract to target JAR" method was what I previously used and gave me the exact same issue described by OP. I have since changed this method to"try copy to the output directory and link via manifest" method when creating Jar" and I am no longer receiving the error "Error: Could not find or load main class".

Hope this helps save people stuck in my situation a few headaches!

make sure both msssql driver version and jdbcauth version both are same. I am using gradle, it solved by adding these two lines.

   compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '8.2.0.jre8'
        compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc_auth', version: '8.2.0.x64'
    
    and add metadatasource:
     maven {
            url "https://repo.maven.apache.org/maven2"
            metadataSources{
                mavenPom()
                artifact()
            }
    
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM