我加了一句 Ubuntu 20.04
在ad域控制器下并已安装 MsSQL
ubuntu机器上的服务器。
我的 sqlcmd localhost
与windows身份验证完美结合
$ sqlcmd -S localhost
1> select @@version
2> GO
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Microsoft SQL Server 2019 (RTM-CU10) (KB5001090) - 15.0.4123.1 (X64)
Mar 22 2021 18:10:24
Copyright (C) 2019 Microsoft Corporation
Developer Edition (64-bit) on Linux (Ubuntu 20.04.2 LTS) <X64>
(1 rows affected)
1>
现在,我试着用简单的java代码来连接它
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* This program demonstrates how to establish database connection to Microsoft
* SQL Server.
*
*/
public class JdbcSQLServerConnection {
public static void main(String[] args) {
Connection conn = null;
try {
String dbURL = "jdbc:sqlserver://170.18.xx.xx:1433;integratedSecurity=true";
String user = "sa";
String pass = "*****************";
conn = DriverManager.getConnection(dbURL, user, pass);
if (conn != null) {
DatabaseMetaData dm = (DatabaseMetaData) conn.getMetaData();
System.out.println("Driver name: " + dm.getDriverName());
System.out.println("Driver version: " + dm.getDriverVersion());
System.out.println("Product name: " + dm.getDatabaseProductName());
System.out.println("Product version: " + dm.getDatabaseProductVersion());
}
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
try {
if (conn != null && !conn.isClosed()) {
conn.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
}
我运行这个源代码 java -cp mssql-jdbc-8.4.1.jre8.jar:sqljdbc4.jar:. -Djava.library.path=mssql-jdbc_auth-8.4.1.x64.dll JdbcSQLServerConnection
它抛出异常 Caused by: java.lang.UnsatisfiedLinkError: no mssql-jdbc_auth-8.4.1.x64 in java.library.path
我发现下面有几个未回复的线程,但不确定他们是否在任何dc下添加了机器
java.library.path中没有mssql-jdbc\u auth-8.4.1.x64
linux上java.library.path中没有mssql jdbc auth-8.4.1.x64
https://github.com/microsoft/mssql-jdbc/issues/1453
1条答案
按热度按时间8tntrjer1#
似乎这是久违的答案,我终于能够连接到
MsSQL Server 2019
安装在Ubuntu 20.04
我所需要的是使用下面的db url语法,我不需要传递任何DLL
或者auth
文件。"jdbc:sqlserver://172.18.44.171:1433;integratedSecurity=true;authenticationScheme=javaKerberos;authentication=NotSpecified";
我只是跑了java -cp mssql-jdbc-8.4.1.jre8.jar:. JdbcSQLServerConnection
请参阅这里的讨论通过jdbc从linux机器连接到具有windows身份验证的sqlserver