Guest User

Untitled

a guest
Jan 22nd, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. public String execute() throws SQLException {
  2. String returnPage = "ERROR";
  3. Connection connection = null;
  4. try {
  5. Class.forName("org.postgresql.Driver");
  6. connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/Dislocation", "user","pass");
  7.  
  8. String sql = "SELECT username FROM User_Login WHERE";
  9. sql+=" username = ? AND password = ?";
  10.  
  11. PreparedStatement stmt = connection.prepareStatement(sql);
  12. stmt.setString(1, this.getUsername());
  13. stmt.setString(2, this.getPassword());
  14.  
  15. ResultSet resultSet = stmt.executeQuery(); // causing error
  16.  
  17. while (resultSet.next()) {
  18. this.username = resultSet.getString(1);
  19. this.password = resultSet.getString(2);
  20. returnPage = "SUCCESS";
  21. }
  22.  
  23. } catch (ClassNotFoundException ex) {
  24. returnPage = "ERROR";
  25. ex.getMessage();
  26. } finally {
  27. if (connection != null) {
  28. connection.close();
  29. }
  30. }
  31. return returnPage;
  32. }
Add Comment
Please, Sign In to add comment