文件名称:关于jsp中的树形节点
文件大小:4.22MB
文件格式:RAR
更新时间:2013-05-11 17:12:36
JAVA,树形,节点
package com.svse.struts.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.svse.struts.entity.PartBean; import com.svse.struts.util.DBConnection; public class PartDao { private Connection conn = null; private PreparedStatement pre = null; private ResultSet rs = null; private DBConnection b = new DBConnection(); /** ******************查询所有部门************************* */ public List getx() { conn = b.getConnection(); List array = new ArrayList(); try { String sql = "select sjid,zjid,zjmc from t_part"; pre = conn.prepareStatement(sql); rs = pre.executeQuery(); while (rs.next()) { int sjid = rs.getInt("sjid"); int zjid = rs.getInt("zjid"); String zjmc = rs.getString("zjmc"); PartBean vo = new PartBean(); vo.setSjid(sjid); vo.setZjid(zjid); vo.setZjmc(zjmc); array.add(vo); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (pre != null) { pre.close(); } if (conn != null) { conn.close(); } } catch (SQLException e1) { e1.printStackTrace(); } } return array; } /** ********************增加部门********************** */ public void addpart(PartBean vo) { conn = b.getConnection(); try { int count = 0; String sql = "select max(zjid) as t from t_part"; String sql1 = "insert into t_part(sjid,zjid,zjmc,zjjs) values(?,?,?,?)"; pre = conn.prepareStatement(sql); rs = pre.executeQuery(); while (rs.next()) { count = rs.getInt("t"); } count = count + 1; pre = conn.prepareStatement(sql1); pre.setInt(1, vo.getSjid()); pre.setInt(2, count); pre.setString(3, vo.getZjmc()); pre.setString(4, vo.getZjjs()); pre.executeUpdate(); pre.close(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (pre != null) { pre.close(); } if (conn != null) { conn.close(); } } catch (SQLException e1) { e1.printStackTrace(); } } } /********************查询单个部门***********************/ public PartBean getdep(int zjid) { PartBean bean=new PartBean(); conn = b.getConnection(); try { String sql="select sjid,zjid,zjmc,zjjs from t_part where zjid=?"; pre=conn.prepareStatement(sql); pre.setInt(1,zjid); rs=pre.executeQuery(); while(rs.next()) { bean.setSjid(rs.getInt("sjid")); bean.setZjid(rs.getInt("zjid")); bean.setZjmc(rs.getString("zjmc")); String tx=null; tx=rs.getString("zjjs"); if(tx==null) { String tt="暂无"; bean.setZjjs(tt); } else { bean.setZjjs(tx); } } } catch(SQLException e) { e.printStackTrace(); } finally { try { if(pre!=null) { pre.close(); } if(conn!=null) { conn.close(); } } catch(SQLException e1) { e1.printStackTrace(); } } return bean; } /**************************修改部门***********************/ public void up(PartBean bean) { conn = b.getConnection(); try { String sql="update t_part set zjmc=?,zjjs=?,sjid=? where zjid=?"; pre=conn.prepareStatement(sql); pre.setString(1,bean.getZjmc()); pre.setString(2,bean.getZjjs()); pre.setInt(3,bean.getSjid()); pre.setInt(4,bean.getZjid()); pre.executeUpdate(); } catch(SQLException e) { e.printStackTrace(); } finally { try { if(pre!=null) { pre.close(); } if(conn!=null) { conn.close(); } } catch(SQLException e1) { e1.printStackTrace(); } } } /********************删除部门**********************/ public int del(int sjid,int zjid) { int s=0; conn = b.getConnection(); String sql="delete from t_part where sjid=? and zjid=?"; try { int count=0;//统计了结点 String sqlCount="select count(*) as t from t_part where sjid=?"; pre=conn.prepareStatement(sqlCount); pre.setInt(1,zjid); rs=pre.executeQuery(); while(rs.next()) { count=rs.getInt("t"); } if(count>0) { s=0;//下面有了结点,不能删除! } else { pre=conn.prepareStatement(sql); pre.setInt(1,sjid); pre.setInt(2,zjid); pre.executeUpdate(); s=1; } } catch(SQLException e) { e.printStackTrace(); } finally { try { if(pre!=null) { pre.close(); } if(conn!=null) { conn.close(); } } catch(SQLException e1) { e1.printStackTrace(); } } return s; } }