public boolean root_IsPass(String id,String pass) throws Exception { String pas = root_GetPassword(id); if(pas!=null) { if(!pas.equals("")) { if (pass != null) { if (BCrypt.checkpw(pass,pas)) return true; else return false; } else return false; } else return false; } else return false; } private String root_GetPassword(String id) throws Exception { String sql="select * from administrators where id = ?"; PreparedStatement pre = connect.prepareStatement(sql); pre.setString(1,id); ResultSet rs = pre.executeQuery(); String password = null; while(rs.next()) { password=rs.getString(2); } pre.close(); if(password!=null) return password; else return null; } public void root_add(int id,String password) throws Exception { String sql = "insert into administrators(id,password) values(?,?);"; PreparedStatement pre = connect.prepareStatement(sql); pre.setInt(1,id); pre.setString(2,BCrypt.hashpw(password,BCrypt.gensalt())); int count=pre.executeUpdate(); pre.close(); } /*student add * 学生增加,将学生信息添加到数据库 * 1.输入参数为:姓名,性别,班级,专业,院系,密码,头像,签名,手机号码 * 2.输入参数为:学号,姓名,性别,班级,专业,院系,密码,头像,签名,手机号码 * */ // public void stu_add(wangzhan.Pd_stu pdd) // { // } public void stu_add(String year,String name,String sex,String classs,String major,String faculty,String pas,Blob ava,String signature,String phone) throws Exception { stu_add(stu_GetNextId(year),name,sex,classs,major,faculty,pas,ava,signature,phone); } public void stu_add(int id,String name,String sex,String classs,String major,String faculty,String pas,Blob ava,String signature,String phone) throws Exception { String sql = "insert into student(stu_id,stu_name,stu_sex,stu_class,stu_major,stu_faculty,stu_pas,stu_ava,stu_signature,stu_phone) values(?,?,?,?,?,?,?,?,?,?);"; PreparedStatement pre = connect.prepareStatement(sql); pre.setInt(1,id); pre.setString(2,name); pre.setString(3,sex); pre.setString(4,classs); pre.setString(5,major); pre.setString(6,faculty); pre.setString(7,BCrypt.hashpw(pas,BCrypt.gensalt())); pre.setBlob(8,ava); pre.setString(9,signature); pre.setString(10,phone); int count=pre.executeUpdate(); pre.close(); }
标签:pre,25,pas,String,setString,stu,2023.4,id From: https://www.cnblogs.com/wllovelmbforever/p/17353536.html