This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
There is a table named channel in my database(sqlServer2000). It�s data structure as follow: The letter c refers to channel.
Description: 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 *** Father102 Father103 Father106 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
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 (results.next())rather than while (results.next()). 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