File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Recursive Java programming method for executing recursive SQL queries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Recursive Java programming method for executing recursive SQL queries" Watch "Recursive Java programming method for executing recursive SQL queries" New topic
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: 30392
    
150

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: 30392
    
150

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: 30392
    
150

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.
 
jQuery in Action, 2nd edition
 
subject: Recursive Java programming method for executing recursive SQL queries