title: ResultSet cannot be resolved to a type
body: <p>I am refactoring two .jsp pages to place some common code to a Java class. The purpose of the common code is to connect to a database.</p>
  
  <p>Both pages were working well before the change. But I now get an "ResultSet cannot be resolved to a type" error on one page, whereas the other page runs without error. I do not understand why, as I think I made similar changes to both pages.</p>
  
  <p>Could anyone help me explain why the first page does not work, while the first one does?</p>
  
  <p>Here is the page that no longer works after the change: </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en-GB" xml:lang="en-GB"&gt;
  &lt;%@page pageEncoding="utf-8" %&gt;
  
  &lt;head&gt;
      &lt;meta charset="UTF-8" /&gt; 
      &lt;title&gt;Forum&lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href="stocktails.css" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;%@ include file="navigation.html" %&gt;
  
      &lt;div id="maindiv"&gt;
          &lt;header&gt;
              &lt;h1&gt; Discussion forum &lt;/h1&gt;
              &lt;p&gt;Bounce your investing ideas off the community&lt;/p&gt;
          &lt;/header&gt;
  
          &lt;div class="left-col"&gt;
  
              &lt;div id='post'&gt;
                  &lt;form action='post.jsp' method="get"&gt;
                      User name: &lt;input type="text" name="userName"&gt;&lt;br&gt;
                      Password: &lt;input type="password" name="pwd"&gt;
                      &lt;textarea id="postText" name="textarea" rows="10" cols="50"&gt;Type here&lt;/textarea&gt;
                      &lt;input type="submit" value="Submit"&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
  
              &lt;%@ page import="com.stocktails.*" %&gt;
              &lt;%
                  dbConnect dbConnection = new dbConnect();
                  String sqlStr = "SELECT * FROM Posts ORDER BY Id ASC";
                  ResultSet rset = dbConnection.executeQuery(sqlStr);
              %&gt;
  
              &lt;div id="tablePlaceholder"&gt;
                  &lt;form method="get" action="forum.jsp"&gt;
                      &lt;table class='forumTable'&gt;
            &lt;%
                while (rset.next()) {
            %&gt;
                          &lt;tr&gt;
                              &lt;td class="postDate"&gt;Posted on: &lt;%= rset.getDate("Date") %&gt;&lt;/td&gt;
                              &lt;td class="postId"&gt;Post #&lt;%= rset.getInt("Id") %&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td class="postMember"&gt;&lt;%= rset.getString("Member") %&gt;&lt;/td&gt;
                              &lt;td class="postText"&gt;&lt;%= rset.getString("Text") %&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td class="postEmpty"&gt;&lt;/td&gt;
                          &lt;/tr&gt;
            &lt;%
                }
            %&gt;
                  &lt;/table&gt;
                  &lt;br&gt;
                &lt;/form&gt;
              &lt;/div&gt;
  
           &lt;% dbConnection.closeAll(); %&gt;
  
          &lt;/div&gt;
  
          &lt;div class="right-col"&gt;
              &lt;aside class="aside-forum"&gt;
                  &lt;header&gt;
                      &lt;h1&gt; Forum etiquette &lt;/h1&gt;
                      &lt;p&gt; Thou shall not troll &lt;/p&gt;
                  &lt;/header&gt;
                  &lt;section&gt;
                      &lt;h1&gt; No promotion &lt;/h1&gt;
                      &lt;p&gt; Do not use this forum to promote your own business. &lt;/p&gt;
                  &lt;/section&gt;
                  &lt;section&gt;
                      &lt;h1&gt; Keep calm and carry on &lt;/h1&gt;
                      &lt;p&gt; Be courteous. Personal disagreements should be handled through email and not through public posts. &lt;/p&gt;
                  &lt;/section&gt;
                  &lt;section&gt;
                      &lt;h1&gt; No hijacking &lt;/h1&gt;
                      &lt;p&gt; Do not hijack someone else's thread and interrupt a topic of discussion. &lt;/p&gt;
                  &lt;/section&gt;
                  &lt;section&gt;
                      &lt;h1&gt; You say /təˈmeɪtoʊ/, we say /təˈmɑːtəʊ/ &lt;/h1&gt;
                      &lt;p&gt; Please refrain from using American spelling. &lt;/p&gt;
                  &lt;/section&gt;
              &lt;/aside&gt;
          &lt;/div&gt;
  
          &lt;div class="clear"&gt;&lt;/div&gt;
      &lt;/div&gt;
  
      &lt;%@ include file="footer.html" %&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is the error message if get:</p>
  
  <pre><code>HTTP Status 500 - Unable to compile class for JSP:
  
  type Exception report
  
  message Unable to compile class for JSP:
  
  description The server encountered an internal error that prevented it from fulfilling this request.
  
  exception
  
  org.apache.jasper.JasperException: Unable to compile class for JSP: 
  
  An error occurred at line: 37 in the jsp file: /forum.jsp
  ResultSet cannot be resolved to a type
  34:             &lt;%
  35:                 dbConnect dbConnection = new dbConnect();
  36:                 String sqlStr = "SELECT * FROM Posts ORDER BY Id ASC";
  37:                 ResultSet rset = dbConnection.executeQuery(sqlStr);
  38:             %&gt;
  39: 
  40:             &lt;div id="tablePlaceholder"&gt;
  
  
  Stacktrace:
      org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
      org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
      org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  note The full stack trace of the root cause is available in the Apache Tomcat/7.0.52 logs.
  </code></pre>
  
  <p>Here is the other page that still works even after I moved some code to a separate class:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Quote Query&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;retrieve stock quotes&lt;/h1&gt;
    &lt;h3&gt;Choose Ticker(s):&lt;/h3&gt;
    &lt;form method="get"&gt;
      &lt;input type="checkbox" name="ticker" value="AAPL"&gt;AAPL
      &lt;input type="checkbox" name="ticker" value="MSFT"&gt;MSFT
      &lt;input type="submit" value="Query"&gt;
    &lt;/form&gt;
  
    &lt;%
      String[] tickers = request.getParameterValues("ticker");
      if (tickers != null) {
    %&gt;
  
  
          &lt;%@ page import="com.stocktails.*" %&gt;
          &lt;%
              dbConnect dbConnection = new dbConnect();
  
              String sqlStr = "SELECT * FROM Quotes WHERE Ticker IN (";
              sqlStr += "'" + tickers[0] + "'";  // First ticker
              for (int i = 1; i &lt; tickers.length; ++i) {
                  sqlStr += ", '" + tickers[i] + "'";  // Subsequent tickers need a leading commas
              }
              sqlStr += ") ORDER BY Date ASC";
  
              // for debugging
              System.out.println("Query statement is " + sqlStr);
  
              ResultSet rset = dbConnection.executeQuery(sqlStr);
          %&gt;
  
        &lt;hr&gt;
        &lt;form method="get" action="quotes.jsp"&gt;
          &lt;table border=1 cellpadding=5&gt;
            &lt;tr&gt;
              &lt;th&gt;Ticker&lt;/th&gt;
              &lt;th&gt;Date&lt;/th&gt;
              &lt;th&gt;PriceOpen&lt;/th&gt;
              &lt;th&gt;PriceHigh&lt;/th&gt;
              &lt;th&gt;PriceLow&lt;/th&gt;
              &lt;th&gt;PriceClose&lt;/th&gt;
              &lt;th&gt;Volume&lt;/th&gt;
              &lt;th&gt;PriceAdjClose&lt;/th&gt;
            &lt;/tr&gt;
    &lt;%
        while (rset.next()) {
    %&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;%= rset.getString("Ticker") %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%= rset.getString("Date") %&gt;&lt;/td&gt;
              &lt;td&gt;$&lt;%= rset.getInt("PriceOpen") %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%= rset.getInt("PriceHigh") %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%= rset.getString("PriceLow") %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%= rset.getString("PriceClose") %&gt;&lt;/td&gt;
              &lt;td&gt;$&lt;%= rset.getInt("Volume") %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%= rset.getInt("PriceAdjClose") %&gt;&lt;/td&gt;
            &lt;/tr&gt;
    &lt;%
        }
    %&gt;
          &lt;/table&gt;
          &lt;br&gt;
          &lt;input type="submit" value="Order"&gt;
          &lt;input type="reset" value="Clear"&gt;
        &lt;/form&gt;
        &lt;a href="&lt;%= request.getRequestURI() %&gt;"&gt;&lt;h3&gt;Back&lt;/h3&gt;&lt;/a&gt;
    &lt;%
          dbConnection.closeAll();
      }
    %&gt;
  
      &lt;%@ include file="footer.html" %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is the Java class:</p>
  
  <pre><code>import javax.naming.*;
  import java.sql.*;
  import javax.sql.*;
  
  public class dbConnect
  {
      private Context init;
      private Context env;
      private DataSource data;
      private Connection conn;
      private Statement stmt;
      private ResultSet rset;
  
      public dbConnect()
      {
          try {
              init = new InitialContext();
          }
          catch (NamingException e)
          {
              System.out.println("Cannot create initial environment");
          };
  
          try {
              env = (Context) init.lookup("java:/comp/env/");
          }
          catch (NamingException e)
          {
              System.out.println("Cannot create context");
          };
  
          try {
              data = (DataSource) env.lookup("jdbc/mydb");
          }
          catch (NamingException e)
          {
              System.out.println("Cannot create data source");
          };
  
          try {
              conn = data.getConnection();            
          }
          catch (SQLException e)
          {
              System.out.println("Cannot get connection");
          }
  
          try {
              stmt = conn.createStatement();          
          }
          catch (SQLException e)
          {
              System.out.println("Cannot create statement");
          }
  
      }
  
      public ResultSet executeQuery(String sqlStr)
      {
          try {
              rset = stmt.executeQuery(sqlStr);
          }
          catch (SQLException e)
          {
              System.out.println("Cannot execute query");
          }
          return rset;
      }
  
      public void closeAll()
      {
          try {
              rset.close();
              stmt.close();
              conn.close();                       
          }
          catch (SQLException e)
          {
              System.out.println("Cannot close connection");
          }
      }
  }
  </code></pre>