增删改与事务,手动管理Connection

下面是例子:
public boolean add(MissiveRecordViewBean missive,List<UploadFileBean> uploadFileLs) throws BusinessException {
		boolean bool = true;
		Connection conn = DBHelper.getConnection();
		String mUnitInsert = "insert into MISSIVE_UNIT (MISSIVE_ID, TYPE, UNIT_NAME) values (?, ?, ?)";
......
		
		logger.debug("sql: "+missiveAdd);
		try {
			conn.setAutoCommit(false);//开启事务
			Object [] mUnitInsertParams0 = {missive.getMissive_id(),0,missive.getFromUnit()};//
......
			dao.update(conn,missiveAdd, missiveUpdateParams);
			
			dao.update(conn,mUnitInsert, mUnitInsertParams0);
			dao.update(conn,mUnitInsert, mUnitInsertParams1);
			
......			
DBHelper.commitAndCloseQuietly(conn);
		} catch (Exception e) {
			logger.error(e.getMessage());
			bool = false;
			DBHelper.rollbackAndCloseQuietly(conn);
			throw new BusinessException("添加出错");
		} 
		return bool;
	}

你可能感兴趣的:(Connection)