package TSZ1;
import java.sql.*;
public class Rushenzhou {
Connection con;
Statement sta;
ResultSet rs;
String driver;
String url;
String user;
String pwd;
public Rushenzhou()
{
driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName =xiongying";
//test為資料庫名
user = "sa";
pwd = "chenxue";
//請更改為你相應的使用者和密碼
init();
}
public void init()
{
try{
Class.forName(driver);
System.out.println("driver is ok");
con = DriverManager.getConnection(url,user,pwd);
System.out.println("conection is ok");
/* sta = con.createStatement();
rs = sta.executeQuery("select * from room");
while(rs.next())
System.out.println(rs.getInt("roomNum")); */
}catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String args[])
{
Rushenzhou DB=new Rushenzhou();
}
}
在myeclipse的java project中java.lang.ClassNotFoundException:com.mircsoft.jdbc.sqlserver.SQLserverDriver
我確定驅動已經裝了,且升級到了SP3,資料庫表名叫xiongying