错误如下:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
这是DB类
public class DB {
private Connection con;
private String url = "jdbc:sqlserver://localhost:1433; DatabaseName=work_week";
private String user = "sa";
private String password = "picc9518";
public DB(){
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
this.con=DriverManager.getConnection(url,user,password);
}
catch(SQLException e)
{
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("forName wrong~~~~~");
}
}
public Connection getConnection() {
return this.con;
}
public void closed(){
try{
if(con!=null)
con.close();
}
catch(Exception e){
e.printStackTrace();
}
}
我在一个test项目中这样写没输出wrong的
DB db=new DB();
try{
db.getConnection();
System.out.println("as11111adf");
}
catch(Exception ex){
ex.printStackTrace();
System.out.println("Wrong");
}
System.out.println("asdfsadf");
但是Servlet里这样写就出现错误了
try{
DB db=new DB();
conn=db.getConnection();
stmt=conn.prepareCall("{call sp_check_user (?,?)}");
stmt.setString(1, userName);
stmt.setString(2, passWord);
stmt.registerOutParameter(3, java.sql.Types.INTEGER);
stmt.execute();
result=stmt.getInt(1);
}
------解决方案--------------------
mssql的jar包没导入吧
------解决方案--------------------
找不到com.microsoft.sqlserver.jdbc.SQLServerDriver这个类,jar包看看
------解决方案--------------------
要把jar包变成牛奶瓶。。你到referenced libraries中看一下。。看有木有你导入的jar包。。
------解决方案--------------------
jar包没找到