Below is my code in which c1.menu() gives my values from database in Rmenu.
but when compilation proceeds downwards, there is another line ResultSet Rmenu1 = c1.menu1();
which gives me another result set Rmenu1 which have values from database through menu1(); function.

But after execution of its while(Rmenu1.next()) when the cursor comes back to while(Rmenu.next())
it gives error as " Result set is closed".
Is it so that a there can be only one result set at a time or is it a threading issue.

Please help.

try
{
ResultSet Rmenu = c1.menu();
String Strmenu=null;
String UpperStr=null;
String compareStr=null;
int charind;
int n=0;
while(Rmenu.next())
{
Strmenu = Rmenu.getString("HeaderScreenName");
charind = Strmenu.indexOf("-");
UpperStr = Strmenu.substring(0,charind);
if(Strmenu.contains(UpperStr))
{
if(!UpperStr.equals(compareStr))
{
compareStr=UpperStr;
%>
<li>
<a href="#"><% out.println(UpperStr); %></a>
<ul>
<% }
int i=0;
ResultSet Rmenu1 = c1.menu1();
while(Rmenu1.next())
{

if(Strmenu.contains(UpperStr))
{
if(i==0)
{
%>
<li><a href="#"><% out.println(Strmenu.replace(UpperStr+"-","")); %></a></li>
<% i++; }
}
}
} %>

</ul>
</li>
<%}
}
catch(Exception e)
{
out.println(e);
e.printStackTrace();
}

Recommended Answers

All 3 Replies

It is not very efficient reading from ResultSet while generating the html.
Better to have separate class that returns as an array of objects the data you want and then use that data to generate the page.
And the class will be responsible of handling the opening and closing of the ResultSet as well as the connection.

Well, you don't show whatever code "c1.menu1();" is executing, but you can only have one ResultSet open per Statement. You can have multiple Statement objects for a Connection though. Most likely you are re-using the Statement that created "Rmenu".

A few other things to note:
- This is the Java programming forum, but there is a separate forum for JSP and these questions are best directed there.
- You should not have so much Java code in your JSP page. Beans and Servlets should be handling those things.

We thanks for the advice.....I am not sound with tag librarys and el that why as a beginner I used java in jsp. I am learning tag libs, so slowly i will start using them to improve my coding style...

Thanks everyone for the advice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.