The concrete algorithm of implementing the tree structure of forum based on JSP

Source: Internet
Author: User
Tags getmessage mysql stmt table name mysql database

Implementation of the Forum tree structure of the algorithm many, specific you can go to www.chinaasp.com full-text search query. My current JSP forum is also one of the following: Do not have to implement the tree structure of the algorithm, now I will be the forum tree structure of the specific algorithm and you introduce, and everyone to communicate.

1, the structure of the demo table:

Table Name: mybbslist

field Data type description

BBSID Automatic Numbering

Rootid Int Root Post ID, which itself is the root post Rootid = ID

FID INT parent Post ID, the ID of the previous post, if the root thread fid = 0

DEPTH Int Root Post level=0, other depending on the depth of the reply increment

Bbssubject Char Theme

2. To create a table:

create table mybbslist (
  forumID int(20) not null,
  bbsID int auto_increment primary key,
  rootid int(20) not null,
  fid int(20) not null,
  depth 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 (forumID))

3, connect the MySQL database bean

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 (Connurl);
stmt = Conn.createstatement ();
rs = stmt.executequery (SQL);
Return RS;
}
public boolean 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;
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.