日期:2014-05-18  浏览次数:20707 次

java连接数据库出错
很简单的一个测试程序,老是报错
源代码:
import   java.sql.*;
public   class   SqlTesting   {  
public   static   void   main(String   args[])   {  
String   url   =   "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Northwind ";  
String   user   = "sa ";  
String   password   =   "lluuzhou ";  
String   sqlStr   =   "select   CustomerID,   CompanyName,   ContactName   from   Customers ";  

try   {  
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");  
System.out.println(   " "   );  

Connection   con   =   DriverManager.getConnection(   url,   user,   password   );  
Statement   st   =   con.createStatement();  
ResultSet   rs   =   st.executeQuery(   sqlStr   );  

while(rs.next())   {  
System.out.print(rs.getString( "CustomerID ")   +   "   ");  
System.out.print(rs.getString( "CompanyName ")   +   "   ");  
System.out.println(rs.getString( "ContactName "));  
}  
rs.close();  
st.close();  
con.close();  
}   catch(Exception   e)   {  
System.err.print(e);
}  
}  
}

错误异常:
java.lang.ClassNotFoundException:com.microsoft.jdbc.sqlserver.SQLServerDriver
但是我把那三个包都已经放到jdk的lib下了啊,为什么还老是说找不到类呢


------解决方案--------------------
http://support.microsoft.com/kb/313100/zh-cn