Forums Register Login

recursive retrieval

+Pie Number of slices to send: Send
hi! all, in one of my program i've certain data in parent child relationship. like parent A has child B and B has children C1, C2, and C3. And in my java program i'm retrieving this data using recursion.

public void child(String str ) throws Exception
{
ResultSet rs=s.executeQuery("select uid from tree where parent='"+str+"' ");
while(rs.next())
{
String abc= rs.getString(1);
System.out.println(abc);
child(abc);
}
}
while calling child("A") for the first time inside main i got the output like...
A
B
C1
Resultset is closed.
I want to print all the C1, C2, and C3 child nodes.
I've MSAccess at backend.
regards
--prateek
+Pie Number of slices to send: Send
not gonna work using the jdbc dbc bridge. The maximum number of statements you can have open per connection is 1. So upon entering every child node, you execute a new statement which will automatically close the previous resultset/statement. So once you start moving back up to the top of the recursion, none of the previous existing resultsets are open. Thus, the error "resultset is closed"
Solutions:
- have one connection per level of recursion so that every statement/resultset can use its own connection. This is an time expensive task, so it probably shouldn't be done dynamically.
- pass down an array of all the possible values so that you can close your resultset/statement and not include it the recursion. This could be memory intensive depending on the number of matches and the number of recursive calls made.
any other ideas?
Jamie
+Pie Number of slices to send: Send
passing down an arrayList is something like this:

I think that will also work...don't have time to double check it though

[This message has been edited by Jamie Robertson (edited November 28, 2001).]
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 727 times.
Similar Threads
No output classes
overriding + overloading
Garbage collection doubt
Help with Dan's Chapter 6, exam 1, question 8.
how many objects will be eligible for garbage collection
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 00:24:44.