• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Executing one resultset inside another

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
My problem is something like this. I have a Master table and a Transaction table. I am executing a query which retrieve all the Ids from Master table and then as the Ids are getting from resultset i want to fire another query (while the first resultset is executing) which gets data from Transaction table if it has the record of same Id as of Master.
Coding is as follows:
query = "Select Id,Name from Master" ;
while(r.next()){
CompId = r.getInt("Id") ;
System.out.println(r.getString("Name")) ;
query = "Select Distinct(TransId) from Transaction where TransId = "+CompId ;
r1 = s.executeQuery(query) ;
while(r1.next()){
System.out.println(r1.getInt("TransId")) ;
}
}
while executing this the first resultset (r in our case) gets closed automatically. can anyone help me solving this problem.
Thank You.
Nilesh Soni
------------------
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
query = "Select Id,Name from Master" ;
while(r.next()){
CompId = r.getInt("Id") ;
System.out.println(r.getString("Name")) ;
query = "Select Distinct(TransId) from Transaction where TransId = "+CompId ;
r1 = s.executeQuery(query) ;
while(r1.next()){
System.out.println(r1.getInt("TransId")) ;
}
}
The first thing I would do is try a simple join as in:
query = "Select Id, Name, Distinct(TransId) from Master, Transaction where (TransId = Id)"
The reason the resultSet might be getting closed out is because it reaches the end of the rows selected for. Make sure you are getting the data you expect. Another reason might be that your JDBC driver is buggy.
Julio Lopez
M-Group Systems
[This message has been edited by Julio Lopez (edited June 07, 2001).]
 
Nilesh Soni
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
julio,
thanx for your efforts, but what i wanted was not so simple as you have understood. i wanted the rows of master tables also which has no similar records in transaction table. finally i got the solution by using left outer join. may be i was not able to write the exact solution what i wanted. but any way thanx.
bye
------------------
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic