SQL Server 支援 Windows 整合認證 (NTLM/Kerberos),Java 透過 Microsoft JDBC 驅動實現免帳密連線,需部署原生 sqljdbc_auth.dll。
SQLServerDataSource ds = new SQLServerDataSource();
ds.setIntegratedSecurity(true); // 關鍵:啟用整合認證
ds.setServerName("host\\instance");
ds.setPortNumber(1433);
ds.setDatabaseName("AdventureWorksLT2008");
Connection conn = ds.getConnection(); // 使用當前 Windows 使用者身分
String url = "jdbc:sqlserver://host\\instance:1433;" +
"databaseName=AdventureWorksLT2008;" +
"integratedSecurity=true;";
Connection conn = DriverManager.getConnection(url);
sqljdbc_auth.dll (x86/x64/IA64)JRE/lib/ext/ 或 PATH 目錄| 維度 | SQL 認證 | Windows 整合認證 |
|---|---|---|
| 連線字串 | user=sa;password=xxx | integratedSecurity=true |
| 原生庫 | 不需要 | 必需 sqljdbc_auth.dll |
| 認證管理 | 資料庫內建 | Active Directory / 本機帳號 |
| 安全性 | 密碼輪換需求 | 單一登入、群組策略 |
| 跨平台 | 支援 | 僅 Windows (需 DLL) |