JSP 动态树的实现(4)


package com.sx.mas.beans;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import com.sx.mas.utils.DBConn;
public class TreeDAO {
public Vector getTree(){
Vector vec = new Vector();
DBConn dbconn = new DBConn();
Connection conn = dbconn.getConnection();
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from trees");
while(rs.next()){
TreeNode treenode = new TreeNode();
treenode.setTid(rs.getInt("tid"));
treenode.setPid(rs.getInt("pid"));
treenode.setTname(rs.getString("tname"));
treenode.setIsleaf(rs.getInt("isleaf"));
vec.add(treenode);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return vec;
}
}
package com.sx.mas.beans;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import com.sx.mas.utils.DBConn;
public class TreeDAO {
    public Vector getTree(){
        Vector vec = new Vector();
        DBConn dbconn = new DBConn();
        Connection conn = dbconn.getConnection();
        try {
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("select * from trees");
            while(rs.next()){
                TreeNode treenode = new TreeNode();
                treenode.setTid(rs.getInt("tid"));
                treenode.setPid(rs.getInt("pid"));
                treenode.setTname(rs.getString("tname"));
             treenode.setIsleaf(rs.getInt("isleaf"));
                vec.add(treenode);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return vec;
    }
}


第七步:页面上显示树状结构。在TreeDemo中创建show_tree.jsp页面,代码如下。

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzfssx.html