主题:jsp中SQL连接的问题,急!~
在jsp文件中可以连接SQL数据库,但是写了个javabean就连接不了,提示是:java.sql.SQLException: No suitable driver found for jdbc.mysql...驱动我已经导入了,又放进lib里面了,就是奇怪为什么连接不了啊?我已经搞了好多天了,javabean的代码如下:package login;
import java.sql.*;
public class UserBean {
private String username;
private String password;
public void setUsername(String _username) {
this.username=_username;
}
public String getUsername(){
return this.username;
}
public void setPassword(String _password) {
this.password=_password;
}
public String getPassword(){
return this.password;
}
public boolean checklogin(){
boolean loginflag=false;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc.mysql://127.0.0.1:3306/login","root","709394");
stmt=con.createStatement();
String sql="select * from user where username='"+username+"'";
rs=stmt.executeQuery(sql);
while(rs.next())
{
if(password.equals(rs.getString("password")))
{loginflag=true;}
}
}catch(Exception sqlex1)
{
sqlex1.printStackTrace();
} finally {if(con!=null){
try{con.close();}catch(SQLException sqlex2)
{
sqlex2.printStackTrace();
}
}
}return loginflag;
}}
[em18][em18][em18]
import java.sql.*;
public class UserBean {
private String username;
private String password;
public void setUsername(String _username) {
this.username=_username;
}
public String getUsername(){
return this.username;
}
public void setPassword(String _password) {
this.password=_password;
}
public String getPassword(){
return this.password;
}
public boolean checklogin(){
boolean loginflag=false;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc.mysql://127.0.0.1:3306/login","root","709394");
stmt=con.createStatement();
String sql="select * from user where username='"+username+"'";
rs=stmt.executeQuery(sql);
while(rs.next())
{
if(password.equals(rs.getString("password")))
{loginflag=true;}
}
}catch(Exception sqlex1)
{
sqlex1.printStackTrace();
} finally {if(con!=null){
try{con.close();}catch(SQLException sqlex2)
{
sqlex2.printStackTrace();
}
}
}return loginflag;
}}
[em18][em18][em18]