JSP实现树型组织架构(6)--包含文件connectinDB.jsp & orgConnInclude.jsp

//connectionDB.jsp

<%@ page contentType="text/html;charset=Big5"%>
<%@ page import="java.sql.*"%>
<%
Connection conn=null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@192.168.56.199:1521:asdb";
String user="system";
String password="oracle01";
conn=DriverManager.getConnection(url, user, password);
}
catch(Exception e1)
{e1.printStackTrace();}


%>

//orgConnInclude.jsp

<%@ page import="java.sql.*"%>

<%
  Connection conn=null;
  try{
  Class.forName("oracle.jdbc.driver.OracleDriver");
  String url="jdbc:oracle:thin:@192.168.56.199:1521:asdb";
  String user="System";
  String password="oracle01";
  conn=DriverManager.getConnection(url, user, password);}
  catch(Exception se1)
  {se1.printStackTrace();}
%>

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; } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值