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; } }
最近下载更多
asddwh LV12
1月3日
zhtssss LV1
2023年7月4日
oracleanacarge LV5
2023年7月3日
mrcao95 LV2
2023年6月26日
女王不该在山炮村养花 LV8
2023年4月16日
李亮 LV19
2023年3月6日
Numpile LV3
2023年3月1日
poipoiiop LV8
2023年1月3日
000666 LV10
2022年12月23日
微信网友_6263159342649344 LV7
2022年12月15日
最近浏览更多
周青松197 LV1
3月7日
asddwh LV12
2023年12月29日
微信网友_6792227559149568
2023年12月24日
暂无贡献等级
颜菜菜 LV2
2023年12月23日
无名氏111 LV32
2023年11月14日
lyq6666666 LV5
2023年10月23日
jiemomo LV12
2023年10月19日
qq573914838 LV5
2023年10月14日
lwlwlwlw LV3
2023年9月25日
苏柒 LV10
2023年9月20日