英文:
Jar not getting executed in other's pc [problem with JDBC external jar/maven dependency, connection not getting established]
问题
我已经编写了一个使用JDBC连接数据库的代码,我正在使用openJDK11.0.2,64位,以及外部的jar包[mssql-jdbc-8.4.0.jre11](我将其添加到了eclipse中“属性”下的库中)。
我还添加了一个Maven依赖项
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>8.4.0.jre11</version>
</dependency>
因此,在我的代码中,我正在使用Windows身份验证,我的代码如下:
public static void main(String[] args) throws SQLException {
String connString = "jdbc:sqlserver://" + serverName + "\\MSSQLSERVER:1433;" + "databaseName = testUserDb; integratedSecurity = true;";
System.out.print("\nConnection String : " + connString + "\n");
conn = DriverManager.getConnection(connString);
System.out.println("\nConnection Established");
System.out.println("\nSuccess");
}
我将我的代码导出为一个可运行的JAR文件,当我使用java -jar demoJava.jar执行我的JAR文件时,代码运行良好。
但是当我将我的JAR文件交给我的合作伙伴,在他的计算机上(使用相同版本的Java),他遇到了错误,无法建立连接。
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication
有没有办法让我的代码变得通用,并且可以在任何地方运行(当我将其导出为可运行的JAR文件时,外部的mssqljdbc jar包已经包含在我的JAR文件中),但它只能在我的系统中执行。
我错过了什么?与驱动程序DLL有关的问题吗?请提供建议。
英文:
I have written a code to connect to a database using JDBC, I am using openJDK11.0.2, 64 bit, and external jar [mssql-jdbc-8.4.0.jre11] (which i added to libraries inside "properties" in eclipse)
I added a maven dependency as well
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>8.4.0.jre11</version>
</dependency>
So in my code, I am using windows authentication and my code looks like this,
public static void main(String[] args) throws SQLException {
String connString = "jdbc:sqlserver://" + serverName + "\\MSSQLSERVER:1433;" + "databaseName = testUserDb; integratedSecurity = true;";
System.out.print("\nConnection String : " + connString + "\n");
conn = DriverManager.getConnection(connString);
System.out.println("\nConnection Established");
System.out.println("\nSuccess");
}
I exported my code as a runnable jar, and the code is running fine when I am executing my jar using java -jar demoJava.jar
But when I gave my jar to my partner, on his computer (using same version of java) on his I got error, connection is not getting established.
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication
It there a way I can make my code universal, and it will run anywhere (when I am exporting as a runnable jar, the external mssqljdbc jar is present in my JAR) but it is only getting executed in my system.
What am I missing? Something to do with driver dlls? Please suggest.
答案1
得分: 1
只需将**"mssql-jdbc_auth-8.4.0.x64.dll"**添加到其他人的jdk_version/bin目录中,然后重新运行该过程,它就能正常工作。我曾遇到相同的问题。这就是我解决它的方法。
请确保使用正确的版本(64位/86位)。
英文:
Just add "mssql-jdbc_auth-8.4.0.x64.dll" to other peoples jdk_version/bin and rerun the process, it will work, I faced same problem. That is how I resolved it.
Make sure to use correct version (64/86)
答案2
得分: 0
这个错误信息的谷歌搜索结果中的第一个链接指向了 Microsoft 的文档:
其中写道:“这通常表示驱动程序在 JVM 库路径中找不到适当的 sqljdbc_auth.dll。”
在那里有一个修复建议,可以指定 DLL 的路径,前提是你有这个 DLL 文件。当然,这只适用于 Windows 系统。
一个更通用的方法是使用纯 Java 的 JDBC 驱动,比如 jTDS JDBC 驱动。
英文:
The very first Google result for this error message leads to documentation at Microsoft :
which says "This generally indicates that the driver can not find the appropriate sqljdbc_auth.dll in the JVM library path."
There's a fix recommend there for specifying the path to the DLL, assuming that you have it. Of course, that would only work on Windows.
A more universal approach would be to use a pure-java JDBC driver, like the jTDS JDBC Driver.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论