Guest User

Untitled

a guest
Sep 15th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. java.sql.SQLException: Invalid operation: wasNull() called with no data retrieved . But I 'am' checking if it was null
  2. ResultSet set = statement.executeQuery();
  3. // userName = set.getString(1);
  4. if(set.next()) {
  5. userName = set.getString("FirstName");
  6. Email = set.getString("Email");
  7. }
  8. if(set.wasNull()) { //<<------------- line 33
  9. // turn to the error page
  10. response.sendRedirect("LoginFailure.jsp");
  11. } else {
  12. // start the session and take to his homepage
  13. HttpSession session = request.getSession();
  14. session.setAttribute("UserName", userName);
  15. session.setMaxInactiveInterval(900); // If the request doesn't come withing 900 seconds the server will invalidate the session
  16. RequestDispatcher rd = request.getRequestDispatcher("portfolio_one.jsp");
  17. rd.forward(request, response); // forward to the user home-page
  18. }
  19.  
  20. INFO: java.sql.SQLException: Invalid operation: wasNull() called with no data retrieved.
  21. at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
  22. at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
  23. at org.apache.derby.client.am.ResultSet.wasNull(Unknown Source)
  24. at com.sun.gjc.spi.base.ResultSetWrapper.wasNull(ResultSetWrapper.java:141)
  25. --------->> at projectcodes.ValidateDataForSignIn.doPost(ValidateDataForSignIn.java:33)
  26. ..........
  27.  
  28. if(set.next()) {
  29. userName = set.getString("FirstName");
  30. Email = set.getString("Email");
  31.  
  32. // start the session and take to his homepage
  33. HttpSession session = request.getSession();
  34. session.setAttribute("UserName", userName);
  35. session.setMaxInactiveInterval(900); // If the request doesn't come withing 900 seconds the server will invalidate the session
  36. RequestDispatcher rd = request.getRequestDispatcher("portfolio_one.jsp");
  37. rd.forward(request, response); // forward to the user home-page
  38. } else {
  39. // turn to the error page
  40. response.sendRedirect("LoginFailure.jsp");
  41. }
  42.  
  43. User user = userDAO.find(username, password);
  44.  
  45. if (user != null) {
  46. request.getSession().setAttribute("user", user);
  47. request.getRequestDispatcher("portfolio_one.jsp").forward(request, response);
  48. } else {
  49. response.sendRedirect("LoginFailure.jsp");
  50. }
  51.  
  52. public User find(String username, String password) throws SQLException {
  53. Connection connection = null;
  54. PreparedStatement statement = null;
  55. ResultSet resultSet = null;
  56. User user = null;
  57.  
  58. try {
  59. connection = database.getConnection();
  60. statement = connection.prepareStatement("SELECT id, username, email, firstname, lastname, FROM user WHERE username = ? AND password = MD5(?)");
  61. statement.setString(1, username);
  62. statement.setString(2, password);
  63. resultSet = statement.executeQuery();
  64.  
  65. if (resultSet.next()) {
  66. user = new User();
  67. user.setId(resultSet.getLong("id"));
  68. user.setUsername(resultSet.getString("username"));
  69. user.setEmail(resultSet.getString("email"));
  70. user.setFirstname(resultSet.getString("firstname"));
  71. user.setLastname(resultSet.getString("lastname"));
  72. }
  73. } finally {
  74. close(resultSet, statement, connection);
  75. }
  76.  
  77. return user;
  78. }
Add Comment
Please, Sign In to add comment