Advertisement
Guest User

Untitled

a guest
May 30th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. public class LoginDAO {
  2. private Connection connection;
  3.  
  4. public LoginDAO() throws SQLException{
  5. String jdbs = "jdbc:postgresql://localhost:5432/postgres?currentSchema=chatroom";
  6. String user = "postgres";
  7. String password = "171025";
  8.  
  9. connection = DriverManager.getConnection(jdbs, user, password);
  10.  
  11. System.out.println("DB connetion successful to " + jdbs);
  12. }
  13.  
  14. public void register(String username, String password) throws SQLException{
  15.  
  16. }
  17. public boolean login(String username, String password) throws SQLException{
  18.  
  19. PreparedStatement myStmt = connection.prepareStatement(
  20. "SELECT password FROM login WHERE username=?"
  21. );
  22. myStmt.setString(1, username);
  23. ResultSet rs = myStmt.executeQuery();
  24. while(rs.next()){
  25.  
  26. String passwordCheck = rs.getString("password");
  27.  
  28. if(passwordCheck.equals(password)){
  29. return true;
  30. }
  31. }
  32. return false;
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement