读书人

Connection对象一直没被释放

发布时间: 2012-11-09 10:18:48 作者: rapoo

Connection对象一直没有被释放
以下这个方法的目的是
1.先更新表sys_enterprise 里的一条记录
2.在到sys_staffs插入一条记录
3.然后 执行存储过程建里俩个表

问题是 为什么我执行成功后?到sql 2000 的查询分析器里运行

select * from sys_staffs 觉得表里的锁一直没释放呢?
难道每个 con 都要写一个 con.commit()函数

public boolean checkEnterprise(String id){boolean flag = false;EnterpriseEntity enterprise = this.getEnterpriseById(id);String sql = "update sys_enterprise set e_isallowed = 1 where e_id = ?";Connection con = dbc.getConnection();CallableStatement cst = null;PreparedStatement pst = null;ResultSet rs = null;try {con.setAutoCommit(false);pst = con.prepareStatement(sql);pst.setString(1, id);pst.executeUpdate();con = null;con = dbc.getConnection();con.setAutoCommit(false);sql = "insert into sys_staffs(s_name,s_pwd,s_enterprisename) values(?,?,?)";pst = con.prepareStatement(sql);pst.setString(1, enterprise.getEname());pst.setString(2, Secret.getMD5(enterprise.getEname()));pst.setString(3, enterprise.getEname());pst.executeUpdate();con = null;con = dbc.getConnection();con.setAutoCommit(false);sql = "{call proc_create_enterprise '"+enterprise.getEname()+"'}";cst = con.prepareCall(sql);cst.execute();con.commit();flag = true;} catch (Exception e) {flag = false;try {con.rollback();} catch (SQLException e1) {e1.printStackTrace();}e.printStackTrace();}finally{dbc.close(rs, pst, con);}return flag;}

读书人网 >软件架构设计

热点推荐