title: dynamic mySQL query with increment operator
body: <p>I am trying to create an online quiz application. I have a question table with question#, question and options. The requirement is to display one question and ans in the UI at a time and when user clicks on next proceed to another. I have the below code but the select query is not working when I put 'i'. I tried to put 1 just for debugging and its working.</p>
  
  <pre><code>  &lt;form  name="myform"&gt;  
  
      &lt;table&gt;
  &lt;%
  try
  {
  Class.forName("com.mysql.jdbc.Driver");
  String localhost="jdbc:mysql://localhost:3306/pr1";
  Connection  connection=DriverManager.getConnection(localhost, "root", "root"); 
  Statement st=connection.createStatement();
  
  int i= 1;
  
  ResultSet rs=st.executeQuery("select * from question where Qno=i");    
  while(rs.next())
  {
  %&gt;
              &lt;tr&gt;&lt;td&gt; &lt;%=rs.getString("question")%&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td style="padding: 10px;"&gt;A .&amp;nbsp;&lt;input type="radio" name="option" value="optionA"/&gt;&lt;%=rs.getString("optionA")%&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td style="padding: 10px;"&gt;B .&amp;nbsp;&lt;input type="radio" name="option" value="optionB"/&gt;&lt;%=rs.getString("optionB")%&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td style="padding: 10px;"&gt;C .&amp;nbsp;&lt;input type="radio" name="option" value="optionC"/&gt;&lt;%=rs.getString("optionC")%&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td style="padding: 10px;"&gt;D .&amp;nbsp;&lt;input type="radio" name="option" value="optionD"/&gt;&lt;%=rs.getString("optionD")%&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;input type="submit" name="next" value="Next"/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                      &lt;input type="submit" value="Previous"/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                      &lt;input type="submit" value="Test Summary"/&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;%
  }
  %&gt;
    &lt;/table&gt;
  &lt;%
     if(request.getParameter("next")!=null)
    {i++;
    System.out.print(i);
    }
       rs.close();
  
  
  
      st.close();
      connection.close();
      }
  catch(Exception e)
  {
  
      e.printStackTrace();
      }
  
  %&gt;
    &lt;/form&gt;
  </code></pre>