Reputation: 879
I am a beginner. In my project I am using Java and Mysql. While doing a code I got an error. That code is mentioning below
<%
ResultSet rs=s.fetchtask(userid);
while(rs.next())
{
%>
<table border="1">
<tr><td>
<% int qnid=(rs.getInt("question_id"));
ResultSet rs1=s.fetchqn(qnid);
String qn=rs1.getString("question");
%>
<% out.println(qn);%>
</td></tr>
</table>
<%
}
%>
But when I am not using the second fetch its working
<%
ResultSet rs=s.fetchtask(userid);
while(rs.next())
{
%>
<table border="1">
<tr><td>
<% int qnid=(rs.getInt("question_id"));
%>
<% out.println(qnid);%>
</td></tr>
</table>
<%
}
%>
When I am using this code there is no problem. Please somebody help me. The error showing is
org.apache.jasper.JasperException: An exception occurred processing JSP page /setter.jsp at line 142
139: // ResultSet rs1 = st.executeQuery("SELECT * FROM temp_qb WHERE question_id="+qnid+"");
140: ResultSet rs1=s.fetchqn(qnid);
141: // ResultSet rs1=s.fetchqn(qnid);
142: String qn=rs1.getString("question");
143: %>
144: <% //out.println(qn);
145: %>
Upvotes: 0
Views: 218
Reputation: 879
I have solved it. The problem was only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists. SO by using another statement it can be solved.
Upvotes: 1
Reputation: 7187
With so little to go on, I suggest you try this and see if you still get the same error.
<%
ResultSet rs=s.fetchtask(userid);
while(rs.next())
{
%>
<table border="1">
<tr><td>
<% int qnid=(rs.getInt("question_id"));
ResultSet rs1=s.fetchqn(qnid);
while(rs1.next())
{
String qn=rs1.getString("question");
out.println(qn);
}
%>
</td></tr>
</table>
<%
}
%>
Finally,
Upvotes: 0