User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 402,911 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,055 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 374 | Replies: 2
Reply
Join Date: Feb 2008
Posts: 33
Reputation: brr is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
brr brr is offline Offline
Light Poster

resultset within the resultset

  #1  
Jul 23rd, 2008
iam getting problem while using resultset within resultset like...

  1. while(rs.next()){
  2. .......
  3. ......
  4. s=rs.getString(1);
  5. while(rs1.next()){
  6. ------
  7. -------
  8. }
  9. //after completion of inner result set iam not getting values of outer resultset (null) like
  10. rs.getString(1);//nullpointer exception
  11. if i store in variable like in s above show then getting
  12. eventhough getting likethat but iam not getting next record
  13. mean not calling rs.next()
  14. }//rs.next()
Last edited by peter_budo : Jul 23rd, 2008 at 12:50 pm. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,378
Reputation: masijade is a jewel in the rough masijade is a jewel in the rough masijade is a jewel in the rough masijade is a jewel in the rough 
Rep Power: 8
Solved Threads: 120
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: resultset within the resultset

  #2  
Jul 23rd, 2008
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.
Last edited by masijade : Jul 23rd, 2008 at 12:38 pm.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Jan 2008
Posts: 12
Reputation: senthil_sivanat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
senthil_sivanat senthil_sivanat is offline Offline
Newbie Poster

Re: resultset within the resultset

  #3  
Jul 23rd, 2008
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>
Last edited by peter_budo : Jul 23rd, 2008 at 3:00 pm. Reason: Keep It Spam-Free - Do not spam, advertise, plug your website, or engage in any other type of self promotion.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 3:49 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC