I was about to display questions and their respective options from the questionsDB and optionsDB. I have create two result sets and two queries to do the stuff in nested loop.It works fine in first iteration by displaying the first question and its respective options but after that its not iterating the data.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page import="java.sql.*"%> <% String driverName = "com.mysql.jdbc.Driver"; String connectionUrl = "jdbc:mysql://localhost:3306/"; String dbName = "onlinefeedback"; String userId = "root"; String password = "123456"; try { Class.forName(driverName); } catch (ClassNotFoundException e) { e.printStackTrace(); } Connection connection = null; Statement statement = null; ResultSet resultQuestions = null; ResultSet resultOptions = null; try{ connection = DriverManager.getConnection(connectionUrl+dbName, userId, password); statement=connection.createStatement(); String qsql ="SELECT * FROM questionsDB"; resultQuestions = statement.executeQuery(qsql); while(resultQuestions.next()) { int curQuestion= Integer.parseInt(resultQuestions.getString("qid")); %> <%= resultQuestions.getString("qid") %> <%=resultQuestions.getString("questionmessage") %> <% String osql ="SELECT * FROM optionsDB WHERE qid="+curQuestion; resultOptions = statement.executeQuery(osql); %> <% while(resultOptions.next()) { %> <%=resultOptions.getString("optionmessage") %> <% } } //connection.close(); } catch (Exception e) { e.printStackTrace(); } %>