高分求如何jsp+javabean连接数据库并表现成树型结构实现的资源

zmrljl 2002-11-05 03:36:49
不要javascript!谢谢啊,急1
...全文
20 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zmrljl 2002-12-24
  • 打赏
  • 举报
回复
不错!
seani 2002-12-24
  • 打赏
  • 举报
回复
1。演示表的结构:
表名:mybbslist
字段
数据类型
说明
BBSID 自动编号  
RootID Int 根帖ID,本身为根帖则RootID = ID
FID Int 父帖ID,上一层帖子的ID,如是根帖则FID = 0
DEPTH Int 根帖Level=0,其他依据回复的深度递增
BBSSubject Char 主题



2。创建表:
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数据库的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="mybbs" scope="session" class="netzero.mydb" />
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%
int intRowCount;
out.print("显示论坛树形结构");
out.print("<br><br>");
try {
String sql="select * from mybbslist order by rootid desc,depth,fid,bbsid";
ResultSet rs = mybbs.executeQuery(sql);
if (rs.next())
{
rs.last();
intRowCount=rs.getRow();
out.print("论坛树中有");
out.print(intRowCount);
out.print("个叶子节点");
rs.first();
int j=0;
int Depth = 0;
out.print("<ul>");
while(j<intRowCount)
{
int rsDepth=rs.getInt("Depth");
if (rsDepth<Depth)
{
for(int i=1;i<Depth+1;i=i+1)
{
out.print("</ul>");
}
}
rsDepth=rs.getInt("Depth");
if (rsDepth>Depth)
{
out.print("<ul>");
}
out.print("<li>");



String bbssubject=rs.getString("bbssubject");
out.print(bbssubject);
out.print("</li>");
Depth = rs.getInt("Depth");
j=j+1;
rs.next();
}
out.print("</ul>");
}
else
{
out.print("数据库中无记录");
}
}catch (SQLException E) {
out.println("SQLException: " + E.getMessage());
out.println("SQLState: " + E.getSQLState());
out.println("VendorError: " + E.getErrorCode());
}
%>
<% //关闭mysql连接
try {
if(!mybbs.closeConn());
} catch (Exception ex) {
System.err.println("closeConn: " + ex.getMessage());
}

zhuaqfly 2002-12-24
  • 打赏
  • 举报
回复
英雄啊 给我也发一个吧
zhuaqfly@sina.com
sandsworlf 2002-12-24
  • 打赏
  • 举报
回复
很详细
net_spirit 2002-12-21
  • 打赏
  • 举报
回复
兄弟,能不能给我一个
net_spirit@163.com
outlier 2002-12-21
  • 打赏
  • 举报
回复
给你发了。
zmrljl 2002-12-20
  • 打赏
  • 举报
回复
outlier(阿黑哥):能否给我一份;谢谢 zmrljl@yeah.net
outlier 2002-12-20
  • 打赏
  • 举报
回复
呵呵,我用applet来实现树形结构的。用servlet去数据,用JSP也是一样。
easyinfonet 2002-12-20
  • 打赏
  • 举报
回复
id | parentid

递归就可以实现了
zmrljl 2002-11-06
  • 打赏
  • 举报
回复
兄弟们,出手吧!
zmrljl 2002-11-05
  • 打赏
  • 举报
回复
哈哈我当然知道了,现在时间不允许自己写,着急用!
xue_sharp 2002-11-05
  • 打赏
  • 举报
回复
不用javascript很难

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧