實現論壇樹型結構的算法很多
表名
字段 數據類型 說明
BBSID 自動編號
RootID Int 根帖ID
FID Int 父帖ID
DEPTH Int 根帖Level=
BBSSubject Char 主題
create table mybbslist (
forumID int(
bbsID int auto_increment primary key
rootid int(
fid int(
depth int(
userID int(
bbsUser varchar(
bbsSubject varchar(
bbsContent text
bbsTime varchar(
bbsRead int(
bbsReply int(
INDEX forumID (forumID))
package netzero;
import java
public class mydb
{
String driverName = "org
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String connURL= "jdbc:mysql://localhost/mybbs?user=root&password=how&useUnicode=true&characterEncode=
//String connURL= "jdbc:mysql://localhost/netzerobbs?user=root&password=how";
public mydb()
{
try
{
Class
}
catch (java
{
System
}
}
public ResultSet executeQuery(String sql) throws SQLException
{
conn = DriverManager
stmt = conn
rs = stmt
return rs;
}
public boolean closeConn()
{
try
{
if (rs!=null) rs
if (stmt!=null) stmt
if (conn!=null) conn
return true;
}
catch ( SQLException ex )
{
System
return false;
}
}
}
<jsp:useBean id="mybbs" scope="session" class="netzero
<%@ page contentType="text/html;charset=gb
<%@ page import="java
<%@ page import="java
<%
int intRowCount;
out
out
try {
String sql="select * from mybbslist order by rootid desc
ResultSet rs = mybbs
if (rs
{
rs
intRowCount=rs
out
out
out
rs
int j=
int Depth =
out
while(j<intRowCount)
{
int rsDepth=rs
if (rsDepth<Depth)
{
for(int i=
{
out
}
}
rsDepth=rs
if (rsDepth>Depth)
{
out
}
out
String bbssubject=rs
out
out
Depth = rs
j=j+
rs
}
out
}
else
{
out
}
}catch (SQLException E) {
out
out
out
}
%>
<% //關閉mysql連接
try {
if(!mybbs
} catch (Exception ex) {
System
}
%>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20347.html