File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Who can help me resolve this big problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Who can help me resolve this big problem?" Watch "Who can help me resolve this big problem?" New topic

Who can help me resolve this big problem?

frank yang

Joined: Feb 19, 2002
Posts: 22
There is a table named channel in my database(sqlServer2000). It�s data structure as follow:
The letter c refers to channel.

Channel_is_father:If this column has children, it is inserted 1, otherwise 0.
Column1 is the top column, so it�s channel_father_id is set 0. However the column 3 is the second layer column. Its father is 102 named column2, and so on.
Ok. I want to get the data by the layer structure from database and to display on the web.
For example:

I wrote java codes to realize this function ,but failed. I don�t know why.
My codes:

Output as fellow:
Not Father101
Not Father113
Not Father109

The method channelIsFather is used to verify the column whether or not is father column.if so it return 1 ,but 0;
The method getChannelId is used to retrieve the channelID.If the channel_id is the father column, which will recall the the method itself again till the condition turned false.
Thank u very very much!
[ April 03, 2003: Message edited by: frank yang ]

Look at me and hear me<br />Because I am here<br />Just for that
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
I've not followed in detail what is happening, but you can't possibly expect recursion to work with all those instance variables. Get rid of them! Turn them into method-local variables and things might work a whole lot better. Don't declare all of them at the start of the method -- choose the smallest possible scope for each.
If this is simply one-off testing code, then please disregard the following; otherwise, consider these points: Take care to close() statements and connections in finally clauses. Don't catch and absorb Exception. Try to use the proper data types when retrieving JDBC data: returnID should be an int. If you're querying on the primary key, express that in your code: use if ( than while ( Use PreparedStatement for oft-repeated queries like these. Not only is it more efficient, it can also save you data representation headaches (escaping quotes and other special characters in Strings, formatting date and time, that kind of thing).
- Peter
I agree. Here's the link:
subject: Who can help me resolve this big problem?
It's not a secret anymore!