There are many algorithms of the forum tree structure, and you can go to the full-text search of www.chinaasp.com. The current JSP forum is also a kind of: do not use the algorithm for achieving the tree structure, now I will introduce the specific algorithms of the forum tree structure and everyone to communicate with everyone.
1. Structure of the demo: Name: Mybbslist field data type Description BBSID Auto number rootid int root post ID, itself is the root post rootid = ID FID INT parent post = 0 Depth INT Renal Level = 0, other deep incremental BBSSUBJECT CHAR topics based on reply
2. Create a table:
Create Table Mybbslist (ForumID Int (20) Not Null, BBSID INTO_INCREMENT Primary Key, Rootid Int (20) Not Null, FID INT (20) Not Null, USERID INT (20) Not Null, BBSUSER VARCHAR (24) Not Null, Bbssubject Varchar (100) Not Null, Bbscontent Text, BBSTIME VARCHAR (30), BBSRead Int (20), BBSReply Int (20), Index ForumID)
3, connect the bean in the mysql database
package netzero; import java.sql *; public class mydb {String driverName = "org.gjt.mm.mysql.Driver"; Connection conn = null; Statement stmt = null; ResultSet rs = null; String connURL = "jdbc.: ? mysql: // localhost / mybbs user = root & password = how & useUnicode = true & characterEncode = 8859_1 "; // String connURL =" jdbc:? mysql: // localhost / netzerobbs user = root & password = how "; public mydb () {try {Class .forName (driverName);} catch (java.lang.ClassNotFoundException e) {System.err.println ( "netzero (String):" e.getMessage ());}} public ResultSet executeQuery (String sql) throws SQLException { Conn = drivermanager.getConnection (ConnUR); stmt = conn.createstatement (); rs = stmt.executeQuery (SQL); returnlean closeconn () {trylean closeconn () {try {if (rs! = null) rs.close () ; if (stmt! = null) stmt.close (); if (conn! = null) conn.close (); Return true;} catch (sqlexception ex) {System.err.Println ("CloseConn:" EX. GetMessage ()); Return False;}}} 4, the JSP program in the Forum
" ); try {string sql = "select * from mybbslist Order by rootid desc, defth, fid, bbsid"; resultset = mybbs.executeQuery (sql); if (rs.next ()) {rl.as (); Introwcount = rs.getrow (); out.print ("Intum tree"); out.print (Introwcount); Out.print ("Int Leave Node"); rs.first (); int J = 0; int Depth = 0; OUT.PRINT ("