javasql-servermssql-jdbcjava.library.pathintegrated-security

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


I've added Ubuntu 20.04 under AD Domain controller and have installed MsSQL Server on Ubuntu machine.

My sqlcmd localhost works perfectly with windows authentication

$ 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> 

Now, I'm trying to connect it with Simple Java code as

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();
            }
        }
    }
}

I ran this source code as

java -cp mssql-jdbc-8.4.1.jre8.jar:sqljdbc4.jar:. -Djava.library.path=mssql-jdbc_auth-8.4.1.x64.dll JdbcSQLServerConnection

It throws exception as Caused by: java.lang.UnsatisfiedLinkError: no mssql-jdbc_auth-8.4.1.x64 in java.library.path

I found below few unanswered threads but not sure if they have added their machines under any 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

Solution

  • Seems like this is long requested answer, I finally able to connect to MsSQL Server 2019 installed on Ubuntu 20.04

    what all I need is to use below syntax of DB URL and I don't need to pass any DLL or auth file.

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

    I simply ran

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

    Please refer this discussion here Connect To SQL Server With Windows Authentication From A Linux Machine Through JDBC