Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7841941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:12:26+00:00 2026-06-02T16:12:26+00:00

The follwoing servlet snippet : ResultSet set = statement.executeQuery(); // userName = set.getString(1); if(set.next())

  • 0

The follwoing servlet snippet :

ResultSet set = statement.executeQuery();
       // userName = set.getString(1);
        if(set.next()) {
            userName = set.getString("FirstName");
            Email = set.getString("Email");
        }
        if(set.wasNull()) {  //<<------------- line 33
            // turn to the error page
            response.sendRedirect("LoginFailure.jsp");
        } else {
            // start the session and take to his homepage
            HttpSession session = request.getSession();
            session.setAttribute("UserName", userName);
            session.setMaxInactiveInterval(900); // If the request doesn't come withing 900 seconds the server will invalidate the session
            RequestDispatcher rd = request.getRequestDispatcher("portfolio_one.jsp");
            rd.forward(request, response); // forward to the user home-page
        }

creates the following exceptions :

INFO: java.sql.SQLException: Invalid operation: wasNull() called with no data retrieved.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.ResultSet.wasNull(Unknown Source)
at com.sun.gjc.spi.base.ResultSetWrapper.wasNull(ResultSetWrapper.java:141)
--------->> at projectcodes.ValidateDataForSignIn.doPost(ValidateDataForSignIn.java:33)
    ..........

Why does this exception occur ? The exception occurs due to the highlighted line : 33

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:12:27+00:00Added an answer on June 2, 2026 at 4:12 pm

    This exception can occur when ResultSet#next() has returned false. I.e. there is no row at all and thus no column has been retrieved at all. The ResultSet#wasNull() only applies on the last retrieved column, not on the last retrieved row.

    You need to rearrange your code logic.

        if(set.next()) {
            userName = set.getString("FirstName");
            Email = set.getString("Email");
    
            // start the session and take to his homepage
            HttpSession session = request.getSession();
            session.setAttribute("UserName", userName);
            session.setMaxInactiveInterval(900); // If the request doesn't come withing 900 seconds the server will invalidate the session
            RequestDispatcher rd = request.getRequestDispatcher("portfolio_one.jsp");
            rd.forward(request, response); // forward to the user home-page
        } else {
            // turn to the error page
            response.sendRedirect("LoginFailure.jsp");
        }
    

    More clear would be to refactor all that JDBC mess into a standalone UserDAO DAO class with a User model class which you then use as follows:

    User user = userDAO.find(username, password);
    
    if (user != null) {
        request.getSession().setAttribute("user", user);
        request.getRequestDispatcher("portfolio_one.jsp").forward(request, response);
    } else {
        response.sendRedirect("LoginFailure.jsp");
    }
    

    where the find() method look something like this:

    public User find(String username, String password) throws SQLException {
        Connection connection = null;
        PreparedStatement statement = null;
        ResultSet resultSet = null;
        User user = null;
    
        try {
            connection = database.getConnection();
            statement = connection.prepareStatement("SELECT id, username, email, firstname, lastname, FROM user WHERE username = ? AND password = MD5(?)");
            statement.setString(1, username);
            statement.setString(2, password);
            resultSet = statement.executeQuery();
    
            if (resultSet.next()) {
                user = new User();
                user.setId(resultSet.getLong("id"));
                user.setUsername(resultSet.getString("username"));
                user.setEmail(resultSet.getString("email"));
                user.setFirstname(resultSet.getString("firstname"));
                user.setLastname(resultSet.getString("lastname"));
            }
        } finally {
            close(resultSet, statement, connection);
        }
    
        return user;
    }
    

    This way you end up with more self-documenting and better reuseable/testable code.

    See also:

    • Show JDBC ResultSet in HTML in JSP page using MVC and DAO pattern
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my servlet I have the following code: response.setContentType(application/json);//set json content type PrintWriter out
The following HTML snippet submits the file to UploadHandler which is a servlet. Then
If I create following the Servlet 3.0 specification a web application fragment how can
I have the following in my dispatcher-servlet.xml <?xml version=1.0 encoding=UTF-8?> <beans xmlns=http://www.springframework.org/schema/beans xmlns:mvc=http://www.springframework.org/schema/mvc xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
I'm writing my Servlet application and would like to use the following static method
I have following architecture in my application. Client (GWT) <--calls--> Servlet <--calls--> Service <--calls-->
I have the follwoing Components: patientDiseasesStorage = new Object() patientDiseasesStorage['p158246547'] = [1, 3, 8,
Wireshark captures UDP packets in my LAN with follwoing details Source IP 192.168.1.2 Destination
In our Struts2-Spring application we are using the follwoing lines of code access the
I'm getting the following error: javax.servlet.jsp.JspException: Broken pipe Now I have seen questions/answers with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.