关于ArrayList的问题,,,
郁闷了好久的一个问题,求大神帮忙看一下,不长的代码,,,
文件一
node类:
package vo;
public class Node {
private String nodeId;
private String parentId;
private String nodeName;
public String getNodeId() {
return nodeId;
}
public void setNodeId(String nodeId) {
this.nodeId = nodeId;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public String getNodeName() {
return nodeName;
}
public void setNodeName(String nodeName) {
this.nodeName = nodeName;
}
}
------------------------------------------------------
文件二
DaoTest类:
package dao;
import java.sql.*;
import java.util.*;
import vo.Node;
public class DaoTest {
private Connection conn = null;
public void initConnection() throws Exception {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/tree","root","mysqladmin");
}
public ArrayList<Node> getNodeInfo() throws Exception{
ArrayList<Node> nodes = new ArrayList<Node>();
initConnection();
String sql = "select id,pid,name from t_tree";
Statement stat=conn.createStatement();
ResultSet rs = stat.executeQuery(sql);
while (rs.next()){
Node node = new Node();
//node.setHrefAddress(rs.getString("hrefAddress"));
node.setNodeId(rs.getString("id"));
node.setParentId(rs.getString("pid"));
node.setNodeName(rs.getString("name"));
nodes.add(node);
}
closeConnection();
return nodes;