Advertisement
sorenslothe

getUserFromCredentials

Apr 14th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. public static User getUserFromCredentials(String loginname, String password){
  2.        
  3.         User result = null;
  4.         Connection con = null;
  5.        
  6.         try{
  7.            
  8.             con = JDBCConnectionFactory.getNewConnection();
  9.  
  10.         String sql = "SELECT * FROM User WHERE User.userName = ? AND User.password = ?";
  11.         PreparedStatement prep = con.prepareStatement(sql);
  12.         prep.setString(1, loginname);
  13.         prep.setString(2, password);
  14.         ResultSet res = prep.executeQuery();
  15.          while (res.next()) {
  16.              result = createUserFromResultSet(res);
  17.          }
  18.    
  19.        
  20.        
  21.         } catch(SQLException e) {
  22.            
  23.             e.printStackTrace();
  24.            
  25.         } finally {
  26.             JDBCConnectionFactory.closeConnection(con);
  27.            
  28.     }
  29.         return result;
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement