java.lang.UnsatisfiedLinkError:java.library.path 中没有 sqljdbc_auth

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23949890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 09:18:58  来源:igfitidea点击:

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

javasql

提问by rpirez

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

我为我的 Java 应用程序创建了一个 .jar,当我尝试从 cmd 运行该 .jar 时,出现错误。

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.

我一直在搜索并找到了很多例子,但没有一个适合我。我像我在这里看到的那样将 java.library.path 设置为目录“sqljdbc_auth.dll”,但错误持续存在。

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

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:

我使用命令运行我的 java 应用程序:java -Djava.library.path="my dll path" 并给出:

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
integratedSecurity=false;
0(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.run(jTLogin.java:448) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access0(Unknown Source) at java.awt.EventQueue.run(Unknown Source) at java.awt.EventQueue.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain.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

采纳答案by rpires_098

Got it working...

搞定了...

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

1) 在 Java/JDK/bin 中添加 .dll 和 .jar

2) Added .jar in applications/lib

2) 在applications/lib 中添加.jar

3) Added .dll in windows/system32

3) 在 windows/system32 中添加了 .dll

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

在“路径”系统环境中添加 java/jdk../bin 和 windows/system32。

回答by dermoritz

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

如果您不需要“集成安全性”,您可以使用 url 中的参数将其关闭:

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

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

这对于开发来说应该没问题,但可能也适用于某些生产环境。

回答by Maashu

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

经过一整天的沮丧之后,我终于让它工作了,我需要做的就是@user3320956 的第一个建议的一部分。

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

我将 sqljdbc_auth.dll 添加到我的 JDK\bin 目录(在我的例子中是 C:\Program Files\Java\jdk1.7.0_79\bin),我的 CLASSPATH 中唯一的东西是

import com.microsoft.sqlserver.jdbc.*;

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

在那之后,只要我不使用 -cp 或 -classpath 变量,我就可以在我的班级中使用这个语句:

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

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.):

并连接到远程数据库。这是我的连接字符串(当然,替换 SERVERNAME 和 DBNAME,确保您有权限,确保您的服务器设置为接受 TCP/IP 连接等):

##代码##

HTH!

哼!

Cheers,

干杯,

-Matthew

-马修

回答by TheNewGuy

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

我遇到了与 OP 相同的问题,但我无法根据 user3320956 的回复解决。

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".

我正在使用 Intellij Idea,我发现我可以通过更改创建 .jar 的方法来解决这个问题。“提取到目标 JAR”方法是我以前使用的方法,它给了我 OP 描述的完全相同的问题。从那以后,我将此方法更改为“在创建 Jar 时尝试复制到输出目录并通过清单链接”方法,并且我不再收到错误“错误:找不到或加载主类”。

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

希望这有助于让陷入我困境的人免于头疼!