iam getting problem while using resultset within resultset like...

while(rs.next()){
.......
......
s=rs.getString(1);
        while(rs1.next()){
               ------
              -------
        }
       //after completion of inner result set iam not getting values of outer resultset (null) like
          rs.getString(1);//nullpointer exception
          if i store in variable like in s above show then getting 
            eventhough getting likethat  but iam not getting next record 
                     mean not calling rs.next()
}//rs.next()

Recommended Answers

All 2 Replies

Use a new statement object to retreive the second resultset, as, as the API docs clearly state, executing another SQL command on a statement object will automatically close all previously opened resultsets associated with that statement.

query="select * from login where username='"+username+"'and usertype="+usertype+"";
		ps=con.prepareStatement(query);
		rs=ps.executeQuery();
		while (rs.next())
			 { 
					if (rs.getString("password").equals(password))
						 { 
						 	
							session.setAttribute("userid", rs.getString("userid")); 
							session.setAttribute("usertype", rs.getString("usertype"));				
							session.setAttribute("loginstatus", "1");

							if(rs.getString("userid").equals("0"))
								{
								%>
									<jsp:forward page="adminhome.jsp"></jsp:forward>
								<%	
									
								}
							 if(rs.getString("usertype").equals("2"))
								{
									
								String query1="select designation from emp_work_profile where userid="+session.getAttribute("userid")+"";
								ResultSet rs1=null;
								PreparedStatement ps1=null;
								ps1=con.prepareStatement(query1);
								rs1=ps1.executeQuery();
								while(rs1.next())
								{
								
								
								if(rs1.getString("designation").equals("6")||rs1.getString("designation").equals("7"))
								{
									
								}

This works correctly for me i am using two different result set.


For more codesnippets please visit

<URL SNIPPED>

commented: Another "clever" person with JSP database connectivity -2
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.