i am facing a problem in running multiple queries in jsp page, as it is unable to store the values in the 2nd result set i use in my page.
tha code is written below:

String strQuery = "select * from services ";
 
 ResultSet rs =null;
 ResultSet rs1 = null;
 
 rs = st.executeQuery(strQuery);
 while(rs.next())
 {
        String[] serviceArray;
        serviceArray = request.getParameterValues("services");
 
     for (int i = 0; i < serviceArray.length; i++)
     {
             //Retreive service Name to put in Prof_strig.
             String sql = "select * from services";
             out.println(sql);
             rs1= st1.executeQuery(sql);
             while(rs1.next())
              {
                  <tr>
                       <td><%=rs1.getString(1) %></td>
                        <td> <%=rs1.getString(2) %></td>
                  </tr>
<%        
                  }
               
           }
       }
}
 catch(SQLException e)
{
       e.getMessage();
}
%>

In this code m able to get the values in
rs = st.executeQuery(strQuery);

but when i use the second result set
rs1= st1.executeQuery(sql);
it's unable to retreive values.
It return '0' on using rs1.getrow() function,i.e. no value retrieved.
Kindly help me to sort this out.
I can't guess if there's problem using multiple resultsets or its something else.
Thanks.

Recommended Answers

All 8 Replies

  1. First move that code in servlet, this shouldn't e in page view
  2. Make sure that that second parameter is string and not some other type
  3. Check your logs if there are no exceptions

There's no excpetion on the console. Please specify which second parameter are u talking about. and i didnt tried it on Servlet, Ain't it possible to do that in jsp page, coz m working on JSP only.
I guess there is some problem with multiple resultsets on same page. is there any specific multiple resultset handling procedure in JSP.
I faced the same multiple resultset problem in C too in other project, but it was solved by using the direct mysql-api commands and using different resultset variables for all queries and closing them properly after use.

Friend i think you have error in

#
String[] serviceArray;
#
serviceArray = request.getParameterValues("services");

this statement because below code works perfect check it.

<%@page import="java.sql.*,java.io.*;"%>
<% 
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db","****","****");

String strQuery = "select * from services ";

 Statement st=con.createStatement();
  Statement st1=con.createStatement();

ResultSet rs =null;

ResultSet rs1 = null;

 

rs = st.executeQuery(strQuery);

while(rs.next())

{

//String[] serviceArray;

//serviceArray = request.getParameterValues("services");

 

for (int i = 0; i < 5; i++)

{

//Retreive service Name to put in Prof_strig.

String sql = "select * from services";

//out.println(sql);

rs1= st1.executeQuery(sql);

while(rs1.next())

{

%>
<tr>

<td><%=rs1.getString(1) %></td>

<td> <%=rs1.getString(2) %></td>

</tr>

<%

}

 

}

}

}

catch(SQLException e)

{

e.getMessage();

}

%>

Can you post whole code?

Can you post whole code?

I guess there is no need of that now. My problem has been solved.
Though, Thanks you all for putting your interest in the topic.

Would you care to post your solution for others in similar situation?

could you please let us know how the issue was resolved? We are too facing a similar issue.......

In JSP, I tried to insert values for a textfield where the textfield runs according to condition in WHILE loop.
But i am unable to read all those values from the textfield and insert those into SQL+ database.

1. <%
2. while (rs.next()) {
3. %>
4. <TD>
5. <input type="text" size="2" name="classesattended" id="classesattended" value="1" />
6. </TD>//here i need to read all the values of classesattended everytime
7.
8. * //for inserting i have used prepare statemnet*
9. <% st = con.prepareStatement("update std set ca='"+classesattended+"' where year=1");
10. st.executeUpdate();
11. }%> 

Can i get any help?????

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.