package Dao; import java.sql.Connection; import java.sql.SQLException; import util.DBHelper; import com.mysql.jdbc.PreparedStatement; import com.mysql.jdbc.ResultSet; public class DAO { public static Connection con = null; public static PreparedStatement ps = null; public static ResultSet rs = null; //定义一个方法,用来检查登录,这里传入的两个参数分别是从jsp传过来的账号和密码 public static boolean checkLogin(String username, String password) { con = DBHelper.getConnection();//通过DBHelper得到Connection String sql = "select * from login where username = ?";//查询语句,先把username设置为?,后面在赋值 try { ps = (PreparedStatement) con.prepareStatement(sql); ps.setString(1, username);//赋值 rs = (ResultSet) ps.executeQuery();//执行查询语句,返回一个ResultSet,这个就是我们数据库里面的user if (rs.next()) { String pwd = rs.getString("password");//找到数据类里面user所对应的passwrod if (pwd.equals(password)) {//把我们从数据库中找出来的password和从jsp中传过来的passwrod比较 return true; //ture代表验证成功 }else{ return false;//false代表验证失败 } }else{ return false; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } rs = null; } if (ps != null) { try { ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } ps = null; } } return false; } }

liulian666 LV2
2024年7月23日
25jsiahs LV2
2024年6月26日
吞吞吐吐她 LV6
2024年6月5日
asddwh LV13
2024年1月3日
zhtssss LV1
2023年7月4日
oracleanacarge LV6
2023年7月3日
mrcao95 LV2
2023年6月26日
女王不该在山炮村养花 LV8
2023年4月16日
李亮 LV19
2023年3月6日
Numpile LV3
2023年3月1日

g1121345342 LV9
4月29日
zhoubowen LV3
2024年12月29日
liulian666 LV2
2024年7月23日
25jsiahs LV2
2024年6月26日
TY0165 LV20
2024年6月22日
微信网友_6808953284677632 LV2
2024年6月21日
1516299986 LV9
2024年6月14日
bw200488 LV6
2024年6月12日
坚持仙蛊
2024年6月12日
暂无贡献等级
吞吞吐吐她 LV6
2024年6月5日