日期:2014-05-17  浏览次数:20717 次

小弟正在做java开发,连接数据库时这段程序报错,不知道怎么解决,求高人指点,十分感谢
小弟正在做java开发,连接数据库时这段程序报错,不知道怎么解决,求高人指点,十分感谢
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

//连接数据库实例
public class Base {
public static void main(String args[]) throws SQLException{
template();
}
static void template() throws SQLException{
String url = "jdbc:sqlserver://localhost;integratedSecurity=true;DatabaseName=日报管理系统"; 
String user = "root";
String password = "root";
java.sql.Connection conn = null;
Statement st = null;
ResultSet rs = null;
try{  
//加载MySql的驱动类  
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("驱动注册成功!");
conn = DriverManager.getConnection(url, user, password);
st = conn.createStatement();
rs = st.executeQuery("select *from 角色管理");
while(rs.next()){
System.out.println(rs.getObject(1)+"\t"+rs.getObject(2)+"\t"+rs.getObject(1)+"\t");
}
}catch(ClassNotFoundException e){  
System.out.println("找不到驱动程序类 ,加载驱动失败!");  
e.printStackTrace() ;  

finally{
// 关闭记录集  
try{ 
if(rs != null)  
rs.close() ;  
}finally{  
try{ 
if(st != null)
st.close() ;  
}finally{
if(conn != null){ // 关闭连接对象  
try{  
conn.close();
}catch(SQLException e){  
e.printStackTrace() ;  

}  
}  
}
}
}
}




Exception in thread "main" java.lang.UnsatisfiedLinkError: com.microsoft.sqlserver.jdbc.AuthenticationJNI.GetDNSName(Ljava/lang/String;[Ljava/lang/String;Ljava/util/logging/Logger;)I
at com.microsoft.sqlserver.jdbc.AuthenticationJNI.GetDNSName(Native Method)
at com.microsoft.sqlserver.jdbc.AuthenticationJNI.GetDNSName(AuthenticationJNI.java:109)
at com.microsoft.sqlserver.jdbc.AuthenticationJNI.<init>(AuthenticationJNI.java:63)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2229)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at java.sq