public Users findUser(String email) { Users user = new Users(); try { Class.forName("com.mysql.jdbc.Driver"); ct = DriverManager.getConnection("jdbc:mysql://localhost:3306/walter", "root", "1234567890"); ps = ct.prepareStatement("select * from users where email=?;"); ps.setObject(1, email); rs = ps.executeQuery(); rs.next(); user.setId(rs.getInt(1)); user.setEmail(rs.getString(2)); user.setUsername(rs.getString(3)); user.setPassword(rs.getString(4)); user.setCity(rs.getString(5)); user.setAddress(rs.getString(6)); } catch (Exception e) { e.getStackTrace(); } 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; } if (ct != null) { try { ct.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } ct = null; } } return user; }
public boolean CheckUser(Users u) { boolean b = false; try { Class.forName("com.mysql.jdbc.Driver"); ct = DriverManager.getConnection("jdbc:mysql://localhost:3306/walter", "root", "1234567890"); ps = ct.prepareStatement("select * from users where email=? and password=?;"); ps.setObject(1, u.getEmail()); ps.setObject(2, u.getPassword()); rs = ps.executeQuery(); if (rs.next()) { b = true; } } catch (Exception e) { 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; } if (ct != null) { try { ct.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } ct = null; } } return b; }