title: how to get the result query one by one in jsp and mysql
body: <p>I am trying to implement as Online Mock exam in JSP, but I have a problem to get the questions one by one, it get connceted for the first time, and show me the first question and answers, but when I click on "next" again, it still show me the first question, I think by clicking on "next" it start querying again. please help me. 
  this is my bean :</p>
  
  <pre><code>database.SQLSelectStatement sqlselect;
  database.SQLSelectStatement sqlselect2;
  static ResultSet questions;
  static ResultSetMetaData rsm;
  static ResultSet answers;
  public void setConnection() throws SQLException {
      if (database.DatabaseManager.getInstance().connectionOK()) {
          sqlselect = new database.SQLSelectStatement("question", "question", "0");
          sqlselect2 = new database.SQLSelectStatement("answers", "question_id", "0");
          questions = sqlselect.executeWithNoCondition();
      }
  }
  public int i=0;
  public String getQuestions() throws SQLException {
      String result = "";
      rsm = questions.getMetaData();
      for (int i = 0; i &lt; rsm.getColumnCount(); i++) {
          result += "&lt;th&gt;" + rsm.getColumnName(i + 1) + "&lt;/th&gt;";
      }
      if (!questions.isLast()) {
          questions.next();
          System.out.println(i+1);
          result += "&lt;tr&gt;";
          result += "&lt;td&gt;" + questions.getInt(1) + "&lt;/td&gt;";
          result += "&lt;td&gt;" + questions.getString(2) + "&lt;/td&gt;";
          result += "&lt;/tr&gt;";
          result += "&lt;tr&gt;";
          sqlselect2.setValue(String.valueOf(questions.getInt(1)));
           answers = sqlselect2.Execute();
  
          while (answers.next()) {
              result += "&lt;tr&gt; &lt;td colspan='2'&gt;&lt;input type='radio' name='answer' value='" + answers.getString(2) + "'&gt; " + answers.getString(2) + "&lt;/td&gt;&lt;/tr&gt;";
          }
          result += "&lt;/tr&gt;";
          answers.close();
      }
      return result;
  }
  </code></pre>
  
  <p>this is the HTML:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;JSP Page&lt;/h1&gt;
          &lt;jsp:useBean id="exam" class="exam.ExamQuestions"&gt;&lt;/jsp:useBean&gt;
  
          &lt;%
          exam.setConnection();                
          %&gt;
          &lt;form  method="post"&gt;
              &lt;table &gt;
  
                  &lt;%=exam.getQuestions()%&gt;
              &lt;/table&gt;
              &lt;input type="submit" name="action" value="next"/&gt;
          &lt;/form&gt;
          &lt;%
          String action = request.getParameter("action");
          if ("next".equals(action)) {
              out.println(request.getParameter("answer"));
          }
  
          %&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>