資源簡介
動態從數據庫中獲取數據,并生成樹,內附帶SQL,并有說明。

代碼片段和文件信息
package?com.dao;
import?java.sql.Connection;
import?java.sql.DriverManager;
import?java.sql.PreparedStatement;
import?java.sql.ResultSet;
import?java.sql.SQLException;
import?java.util.ArrayList;
public?class?DaoTest?{
Connection?con?=?null;
public?Connection?getConnection()?{
Connection?conn?=?null;
String?url?=?“jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=gbk“;
String?user?=?“root“;
String?password?=?“1234“;
try?{
if?(conn?==?null)?{
Class.forName(“com.mysql.jdbc.Driver“).newInstance();
conn?=?DriverManager.getConnection(url?user?password);
}
}?catch?(Exception?e)?{
System.out.println(“連接失敗“);
return?null;
}?finally?{
url?=?null;
user?=?null;
password?=?null;
}
return?conn;
}
public?ArrayList?getNodeInfo()?{
String?sql?=?“select?nodeId?parentId?hrefAddress?nodeName?from?tree_table?order?by?id?“;
PreparedStatement?pre?=?null;
Connection?conn?=?null;
conn?=?getConnection();
ResultSet?rs?=?null;
ArrayList?list?=?new?ArrayList();
try?{
pre?=?conn.prepareStatement(sql);
rs?=pre.executeQuery();
while?(rs.next()){
Nodes?node?=?new?Nodes();
node.setHrefAddress(rs.getString(“hrefAddress“));
node.setNodeId(rs.getString(“nodeId“));
node.setParentId(rs.getString(“parentId“));
node.setNodeName(rs.getString(“nodeName“));
list.add(node);
}
rs.close();
pre.close();
conn.close();
}?catch?(SQLException?e)?{
e.printStackTrace();
}finally{
?pre?=?null;
?conn?=?null;
?rs?=?null;
}
????????return?list;
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????546??2013-08-12?15:13??DtreeTest\.classpath
?????文件????????300??2013-08-12?15:13??DtreeTest\.myme
?????文件???????1415??2013-08-12?15:30??DtreeTest\.project
?????文件????????500??2013-08-12?15:30??DtreeTest\.settings\.jsdtscope
?????文件?????????49??2013-08-12?15:30??DtreeTest\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件??????????6??2013-08-12?15:30??DtreeTest\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????文件???????1661??2013-08-12?15:24??DtreeTest\src\com\dao\DaoTest.java
?????文件????????828??2013-08-12?15:13??DtreeTest\src\com\dao\Nodes.java
?????文件???????1500??2013-08-12?15:13??DtreeTest\src\com\handler\NodesPrint.java
?????文件???????2597??2013-08-13?16:43??DtreeTest\test.sql
?????文件????????795??2013-08-12?15:13??DtreeTest\WebRoot\dtree.css
?????文件??????12410??2013-08-12?15:13??DtreeTest\WebRoot\dtree.js
?????文件???????1040??2013-08-12?15:13??DtreeTest\WebRoot\img\ba
?????文件????????239??2013-08-12?15:13??DtreeTest\WebRoot\img\cd.gif
?????文件?????????62??2013-08-12?15:13??DtreeTest\WebRoot\img\empty.gif
?????文件????????372??2013-08-12?15:13??DtreeTest\WebRoot\img\folder.gif
?????文件????????376??2013-08-12?15:13??DtreeTest\WebRoot\img\folderopen.gif
?????文件???????1095??2013-08-12?15:13??DtreeTest\WebRoot\img\globe.gif
?????文件????????622??2013-08-12?15:13??DtreeTest\WebRoot\img\imgfolder.gif
?????文件?????????69??2013-08-12?15:13??DtreeTest\WebRoot\img\join.gif
?????文件?????????66??2013-08-12?15:13??DtreeTest\WebRoot\img\joinbottom.gif
?????文件?????????66??2013-08-12?15:13??DtreeTest\WebRoot\img\line.gif
?????文件?????????86??2013-08-12?15:13??DtreeTest\WebRoot\img\minus.gif
?????文件?????????85??2013-08-12?15:13??DtreeTest\WebRoot\img\minusbottom.gif
?????文件????????633??2013-08-12?15:13??DtreeTest\WebRoot\img\musicfolder.gif
?????文件????????861??2013-08-12?15:13??DtreeTest\WebRoot\img\nolines_minus.gif
?????文件????????870??2013-08-12?15:13??DtreeTest\WebRoot\img\nolines_plus.gif
?????文件????????582??2013-08-12?15:13??DtreeTest\WebRoot\img\page.gif
?????文件?????????89??2013-08-12?15:13??DtreeTest\WebRoot\img\plus.gif
?????文件?????????88??2013-08-12?15:13??DtreeTest\WebRoot\img\plusbottom.gif
............此處省略33個文件信息
評論
共有 條評論