Ubuntu under AD Domain Controller: UnsatisfiedLinkError: no mssql-jdbc_auth-8.4.1.x64 in java.library.path

Ubuntu under AD Domain Controller: UnsatisfiedLinkError: no mssql-jdbc_auth-8.4.1.x64 in java.library.path

我在 AD 域控制器下添加了 Ubuntu 20.04,并在 Ubuntu 机器上安装了 MsSQL 服务器。

我的 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

  1. no mssql-jdbc_auth-8.4.1.x64 in java.library.path
  2. no mssql-jdbc auth-8.4.1.x64 in java.library.path on linux
  3. https://github.com/microsoft/mssql-jdbc/issues/1453

似乎这是一个长期要求的答案,我终于能够连接到安装在 Ubuntu 20.04

上的 MsSQL Server 2019

我只需要使用下面的 DB URL 语法,我不需要传递任何 DLLauth 文件。

"jdbc:sqlserver://172.18.44.171:1433;integratedSecurity=true;authenticationScheme=javaKerberos;authentication=NotSpecified";

我只是运行

java -cp mssql-jdbc-8.4.1.jre8.jar:. JdbcSQLServerConnection

请参考这里的讨论