Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
arnaud pasquer
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic