标签:代码段 验证方式 连接 .dll sel .exe lap man uri
连接数据库的代码段:
package com.db; import java.sql.*; public class DButil { public static void main(String[] args) { Connection con = null; Statement stmt = null; ResultSet rs = null; String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; String url = "jdbc:sqlserver://10.103.2.18:1433;databaseName=HCM;integratedSecurity=true;";//windows集成模式连接 try { Class.forName(driver); con = DriverManager.getConnection(url); System.out.println("Connecting Successful!!!!!"); stmt = con.createStatement(); rs = stmt.executeQuery("select top 10 * from EmpData"); while(rs.next()){ System.out.println(rs.getString("EmployeeID")+"\t"+rs.getString("Name")); } } catch (SQLException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } finally{ try { rs.close(); stmt.close(); con.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
出现的异常有:
Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
解決方案:
将sqljdbc_auth.dll加入C:\Windows\System32中
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.microsoft.sqlserver.jdbc.AuthenticationJNI.GetDNSName(Ljava/lang/String[Ljava/lang/String;Ljava/util/logging/Logger;)I
解決方案:
1.将sqljdbc4.jar加入工程
2.将sqljdbc_auth.dll文件copy到以下目录
<sqljdbc_auth.dll来自JDBC Driver X.0 for SQL Server,下载网址 http://www.microsoft.com/en-us/download/details.aspx?id=11774 >
java使用windows验证方式连接sqlserver2008数据库
标签:代码段 验证方式 连接 .dll sel .exe lap man uri
原文地址:http://www.cnblogs.com/is-Today/p/7920389.html