1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| public class User { Connection conn = null; PreparedStatement pst = null; ResultSet res = null; boolean isQ;
public boolean Select(String username, String paw) { try { conn = JDBC.getConn(); String sql = "SELECT * FROM user where `Username`=? and `Password`=?;"; pst = conn.prepareStatement(sql); pst.setObject(1, username); pst.setObject(2, paw); System.out.println(sql); res = pst.executeQuery(); if (res.next()) { isQ = true; System.out.println(res.getObject("name") + " " + res.getObject("password")); System.out.println("登陆成功"); } else { isQ = false; System.out.println("登陆失败"); } } catch (Exception e) { System.out.println("NO!"); e.printStackTrace(); } finally { JDBC.release(conn, pst, res); } return isQ; } }
|