title: Getting java.sql.SQLException: Operation not allowed after ResultSet closed ERROR while trying multiple queries
body: <p>I'm trying to fetch data from database based on user input so the user can track orders. The file compiles fine in the IDE but throws this error in the browser:</p>
  
  <blockquote>
    <p>javax.servlet.ServletException: java.sql.SQLException: Operation not allowed after ResultSet closed</p>
  </blockquote>
  
  <p>form.jsp</p>
  
  <pre><code>&lt;form action="viewOrderHistory" method="Post" id="invoiceNumberLookup"&gt;
              Invoice Number:
              &lt;BR&gt;&lt;BR&gt;
              &lt;INPUT TYPE="TEXT" NAME="invoice_number"&gt;
              &amp;nbsp;
              &lt;INPUT TYPE="SUBMIT" value="View Order"&gt;
          &lt;/form&gt;
  
  
              &lt;form action="viewOrderHistory" method="Post" id="referenceNumberLookup"&gt;
              Reference Number:
              &lt;BR&gt;&lt;BR&gt;
              &lt;INPUT TYPE="TEXT" NAME="reference_number"&gt;
              &amp;nbsp;
              &lt;INPUT TYPE="SUBMIT" value="View Order"&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>result.jsp</p>
  
  <pre><code>&lt;%@ page import="java.sql.*" %&gt;
  
  &lt;HTML&gt;
      &lt;HEAD&gt;
          &lt;TITLE&gt;Fetching Data From a Database&lt;/TITLE&gt;
      &lt;/HEAD&gt;
  
      &lt;BODY&gt;
          &lt;H1&gt;Fetching Data From a Database&lt;/H1&gt;
  
          &lt;% 
              Connection connection = DriverManager.getConnection(
                  "jdbc:mysql://localhost/app?user=root&amp;password=password");
  
              Statement statement = connection.createStatement();
  
              String first_name = request.getParameter("first_name");
              String last_name= request.getParameter("last_name");
  
              String invoice_number = request.getParameter("invoice_number");
              String reference_number = request.getParameter("reference_number");
              String amount = request.getParameter("amount");
              String status= request.getParameter("status");
              String date_created = request.getParameter("date_created");
              String quantity = request.getParameter("quantity");
              String product_name = request.getParameter("product_name");
              String product_price = request.getParameter("product_price");
  
              ResultSet resultset = 
  
                      statement.executeQuery("select * from customer where first_name = '" + first_name + "'") ;
              statement.executeQuery("select * from customer where last_name = '" + last_name + "'") ; 
  
  
  
                  statement.executeQuery("select * from customer_order where amount = '" + amount + "'") ;
              statement.executeQuery("select * from customer_order where date_created = '" + date_created + "'") ; 
  
              statement.executeQuery("select * from customer_order where reference_number = '" + reference_number + "'") ; 
              statement.executeQuery("select * from customer_order where invoice_number = '" + invoice_number + "'") ; 
              statement.executeQuery("select * from customer_order where status = '" + status + "'") ; 
              statement.executeQuery("select * from ordered_product where quantity = '" + quantity + "'") ; 
  statement.executeQuery("select * from ordered_product where product_name = '" + product_name + "'") ;
  statement.executeQuery("select * from ordered_product where product_price = '" + product_price + "'") ;
  
              if(!resultset.next()) {
                  out.println("Sorry, could not find that order. ");
              } else {
          %&gt;
  
          &lt;div class="banner"&gt;   
         &lt;% 
             } 
         %&gt;
              &lt;/div&gt;
  
          Invoice Number: &lt;%= resultset.getString("invoice_number") %&gt;
          Reference Number: &lt;%= resultset.getString("reference_number") %&gt;
          Created by: &lt;%= resultset.getString("first_name") %&gt; &lt;%= resultset.getString("last_name") %&gt;
          Date Created: &lt;%= resultset.getString("date_created") %&gt;
          Grand Total: &lt;%= resultset.getString("amount") %&gt;
  
  
          Order:
          &lt;TABLE BORDER="1"&gt;
              &lt;TR&gt;
                 &lt;TH&gt;Product Name&lt;/TH&gt;
                 &lt;TH&gt;Product Price&lt;/TH&gt;
                 &lt;TH&gt;Quantity&lt;/TH&gt;
             &lt;/TR&gt;
             &lt;TR&gt;
                 &lt;TD&gt; &lt;%= resultset.getString("product_name") %&gt; &lt;/TD&gt;
                 &lt;TD&gt; &lt;%= resultset.getString("product_price") %&gt; &lt;/TD&gt;
                 &lt;TD&gt; &lt;%= resultset.getString("quantity") %&gt; &lt;/TD&gt;
             &lt;/TR&gt;
         &lt;/TABLE&gt;
      &lt;/BODY&gt;
  &lt;/HTML&gt;
  </code></pre>