<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());
}
%>