Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

JDBC and use of SQL CONNECT BY and PRIOR for hierachy (son,father)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JDBC and use of SQL CONNECT BY and PRIOR for hierachy (son,father)
I want to have the hierarchy of an object.
the schema of my table is :
HIERARCHY with column SON and column FATHER
person father
father grandfather
my request SQL (on Oracle) is this :
SELECT SON FROM HIERACHY START WITH (SON = ?) CONNECT BY A = PRIOR FATHER
an exemple of the execution with SON=person is this:
person
father
grandfather
but when i execute the request with JDBC,i have juste the first row:
person
the code is:
prepareStatement.setString(1,"person");
resultatRqt = prepareStatement.executeQuery();
resultSet.next(); ->true
resultSet.next(); ->false
i become mad ;-). thanks to help me.
ps:i use the driver Oracle classes12.zip
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use the same type of SQL here at work. We have an EMPLOYEE table with emp_id as the primary key and sup_emp_id as a column which identifies the employees' supervisor, which is very similiar to a son and father relationship. However, when we search the hierarchy, we always start from the supervisor and search downward. This basically gets all employees that reside within the reporting structure for a given supervisor.
In our case, we start from the top of a hierarchy, which is the reverse, I believe, to what you are performing because you are starting with a leaf and getting the hierarchy in reverse, but the concept is still the same.
Here is the query we use. I'm sure you can adjust it to work in the context of your problem.

Raffi
[ June 26, 2003: Message edited by: SAFROLE YUTANI ]
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic