• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executing one resultset inside another

 
Nilesh Soni
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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
------------------
 
Julio Lopez
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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
  • 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
------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic