| Author |
Recursive Java programming method for executing recursive SQL queries
|
Sk Balu
Greenhorn
Joined: Jun 12, 2011
Posts: 3
|
|
Anybody has a Java/JDBC example method to execute recursive SQL queries and print results? The method has to work for any number of queries and levels and the first query passes the parameter to the second query.
Thanks in advance.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
|
Take a look at common table expressions. I'm not sure if they are database specific, but I know postgres and SQL server both have them.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Sk Balu
Greenhorn
Joined: Jun 12, 2011
Posts: 3
|
|
Jeanne Boyarsky wrote:Take a look at common table expressions. I'm not sure if they are database specific, but I know postgres and SQL server both have them.
Thanks Jeanne. I looked at common table expressions but I am looking for Java recursive programming solution to make it database independant.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
|
With Java it's easier. Do the "parent" query and then call the same function with each result until no results are left. Just like any other Java recursion. You might try posting what you get stuck on.
|
 |
Sk Balu
Greenhorn
Joined: Jun 12, 2011
Posts: 3
|
|
Jeanne Boyarsky wrote:With Java it's easier. Do the "parent" query and then call the same function with each result until no results are left. Just like any other Java recursion. You might try posting what you get stuck on.
I am trying to write Java method but If this exists already then I can re-use it and save time.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
Sk Balu wrote:
Jeanne Boyarsky wrote:With Java it's easier. Do the "parent" query and then call the same function with each result until no results are left. Just like any other Java recursion. You might try posting what you get stuck on.
I am trying to write Java method but If this exists already then I can re-use it and save time.
The Java method is going to be specific to your solution not something you can just drop in for reuse.
|
 |
 |
|
|
subject: Recursive Java programming method for executing recursive SQL queries
|
|
|