亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 8076 | 回復(fù): 4
打印 上一主題 下一主題

實(shí)現(xiàn)論壇樹型結(jié)構(gòu)的具體算法 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2001-11-20 10:18 |只看該作者 |倒序?yàn)g覽
作者:flyblue

實(shí)現(xiàn)論壇樹型結(jié)構(gòu)的算法很多,具體你可以去www.chinaasp.com的全文搜索中查詢。我現(xiàn)在的JSP論壇采用的也是當(dāng)中的一種:不用遞歸實(shí)現(xiàn)樹型結(jié)構(gòu)的算法,現(xiàn)在我將論壇樹型結(jié)構(gòu)的具體算法和大家介紹一下,和大家一起交流。

1。演示表的結(jié)構(gòu):
表名:mybbslist
字段
數(shù)據(jù)類型
說明
BBSID 自動(dòng)編號(hào)  
RootID Int 根帖ID,本身為根帖則RootID = ID
FID Int 父帖ID,上一層帖子的ID,如是根帖則FID = 0
DEPTH Int 根帖Level=0,其他依據(jù)回復(fù)的深度遞增
BBSSubject Char 主題

2。創(chuàng)建表:
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。連接MYSQL數(shù)據(jù)庫的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;
}
}

}

4。顯示論壇的JSP程序
<jsp:useBean id=&quot;mybbs&quot; scope=&quot;session&quot; class=&quot;netzero.mydb&quot; />;
<%@ page contentType=&quot;text/html;charset=gb2312&quot; %>;
<%@ page import=&quot;java.io.*&quot; %>;
<%@ page import=&quot;java.sql.*&quot; %>;
<%
int intRowCount;
out.print(&quot;顯示論壇樹形結(jié)構(gòu)&quot;
out.print(&quot;<br>;<br>;&quot;
try {
String sql=&quot;select * from mybbslist order by rootid desc,depth,fid,bbsid&quot;;
ResultSet rs = mybbs.executeQuery(sql);
if (rs.next())
{
rs.last();
intRowCount=rs.getRow();
out.print(&quot;論壇樹中有&quot;
out.print(intRowCount);
out.print(&quot;個(gè)葉子節(jié)點(diǎn)&quot;
rs.first();
int j=0;
int Depth = 0;
out.print(&quot;<ul>;&quot;
while(j<intRowCount)
{
int rsDepth=rs.getInt(&quot;Depth&quot;
if (rsDepth<Depth)
{
for(int i=1;i<Depth+1;i=i+1)
{
out.print(&quot;</ul>;&quot;
}
}
rsDepth=rs.getInt(&quot;Depth&quot;
if (rsDepth>;Depth)
{
out.print(&quot;<ul>;&quot;
}
out.print(&quot;<li>;&quot;

String bbssubject=rs.getString(&quot;bbssubject&quot;);
out.print(bbssubject);
out.print(&quot;</li>;&quot;);
Depth = rs.getInt(&quot;Depth&quot;);
j=j+1;
rs.next();
}
out.print(&quot;</ul>;&quot;);
}
else
{
out.print(&quot;數(shù)據(jù)庫中無記錄&quot;);
}
}catch (SQLException E) {
out.println(&quot;SQLException: &quot; + E.getMessage());
out.println(&quot;SQLState: &quot; + E.getSQLState());
out.println(&quot;VendorError: &quot; + E.getErrorCode());
}
%>;
<% //關(guān)閉mysql連接
try {
if(!mybbs.closeConn());
} catch (Exception ex) {
System.err.println(&quot;closeConn: &quot; + ex.getMessage());
}
%>;


算法參考:http://www.chinaasp.com/sqlbbs/showEssence.asp?id=4783


論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2010-09-23 01:06 |只看該作者
比較有價(jià)值

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2010-09-24 22:09 |只看該作者
代理放到code標(biāo)簽中讀起來會(huì)更方便一些

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2010-10-01 21:06 |只看該作者
有價(jià)值。

論壇徽章:
12
射手座
日期:2014-10-02 11:31:29程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-05-28 06:20:00每日論壇發(fā)貼之星
日期:2016-05-27 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-05-27 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-05-25 06:20:00每日論壇發(fā)貼之星
日期:2016-05-24 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-05-24 06:20:0015-16賽季CBA聯(lián)賽之深圳
日期:2016-05-23 15:33:59程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-05-20 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-04-26 06:20:00神斗士
日期:2015-12-03 09:27:3215-16賽季CBA聯(lián)賽之八一
日期:2016-12-29 09:56:05
5 [報(bào)告]
發(fā)表于 2014-08-28 18:09 |只看該作者
代理放到code標(biāo)簽中有價(jià)值很多
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP