日期:2014-05-20 浏览次数:20910 次
package com.cfd.drp.client; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import com.cfd.drp.utils.Utils; public class ClientManager { StringBuffer sb = new StringBuffer(); private static ClientManager manager = new ClientManager(); private ClientManager() {} public static ClientManager getInstance() { return manager; } public String showTree() { Connection connection = null; sb.delete(0, sb.length()); try { connection = Utils.getConnection(); tree(connection,0,1); }catch(Exception e) { e.printStackTrace(); }finally { Utils.close(connection); } return sb.toString(); } public void tree(Connection connection,int id,int level) throws SQLException { String sql = "select * from t_client where pid = ?"; int i= 0; PreparedStatement ps = null; ResultSet rs = null; try { ps = connection.prepareStatement(sql); ps.setInt(1, id); rs = ps.executeQuery(); while (rs.next()) { sb.append(rs.getString("name")+"<br>"+"\n"); if(rs.getString("is_leaf").equals("N")) { tree(connection,rs.getInt("id"),level); } } }finally { Utils.slose(rs); Utils.close(ps); } } }
<% ClientManager manager = ClientManager.getInstance(); out.print(manager.showTree()); %>
StringBuffer sb = new StringBuffer();