主题:jsp连接数据库的问题,急
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
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