JDBC 事务处理 -java


/**
* 引入明细信息
* 访问资源:ECC_EPM.EPM_TBL_CONTRACT_DETAIL,ECC_EPM.EPM_TBL_SUBCONTRACT_DISPATCH
*
* @param detailsBO
* @return int
* @roseuid 4BA1C4E103C5
*/
public int inductDetailsInfo(DetailsBO detailsBO) throws EccInfoException
{
int result = -1;
// JDBC兄弟
PreparedStatement pstmt = null;
Connection conn = BaseDAO.getConnection();
try
{
//关闭事务自动提交
conn.setAutoCommit(false);
// 因采取直接查询之后插入的SQL有错误,现修改为,JDBC的批量提交方式
StringBuffer sql = new StringBuffer();
sql.append("INSERT INTO ECC_EPM.EPM_TBL_CONTRACT_DETAIL ");
sql.append("(OID,CONTRACT_ID,ITEM_NAME,DATA_TYPE,ITEM_TYPE,DISCTRIPTION, ");
sql.append("UNIT,NUM,PRICE,REMARK,ENABLE_FLAG,CONTRACT_ITEM_ID,DISPATCH_CONTRACT_ITEM_ID, ");
sql.append("CREATED_BY,CREATED_DATE,LAST_UPDATED_BY,LAST_UPDATED_DATE) ");
sql.append("VALUES (ECC_EPM.SUB_PERSONNEL_EVALUE_INFO_S.NEXTVAL, ");
sql.append(" ?,?,?,?,?,?,?,?,?,'T',?,?,?,SYSDATE,?,SYSDATE)");
pstmt = conn.prepareStatement(sql.toString());
// 得到VO
DetailsVO detailsVO = detailsBO.getDetailsVO();
// 根据选择的OID,获取相关的信息
List<DetailsVO> tempList = (List)this.getSqlMapClientTemplate().queryForList("DetailsDAO.queryInductDetails", detailsBO);
// 如果结果列表不为空
if(null != tempList && tempList.size() > 0)
{
DetailsVO tempVO = null;
// 遍历列表,取出相关信息
for(int i = 0,j = tempList.size(); i < j; i++)
{
int k = 1;
// 从列表中取值
tempVO = tempList.get(i);
// 附值
pstmt.setLong(k++, detailsBO.getObjectOid());
pstmt.setString(k++, tempVO.getDetailName());
pstmt.setString(k++, detailsVO.getDataType());
pstmt.setString(k++, detailsVO.getItemType());
pstmt.setString(k++, tempVO.getDetailDesc());
pstmt.setString(k++, tempVO.getDetailUnit());
pstmt.setString(k++, tempVO.getDetailNum());
pstmt.setString(k++, tempVO.getDetailPrice());
pstmt.setString(k++, tempVO.getDetailRemark());
pstmt.setLong(k++, tempVO.getOid());
pstmt.setLong(k++, tempVO.getContractItemId());
pstmt.setLong(k++, detailsVO.getCreatedBy());
pstmt.setLong(k++, detailsVO.getLastUpdatedBy());
pstmt.addBatch();
}
// 批量执行
pstmt.executeBatch();
}
//语句执行完毕,提交本事务
conn.commit();
// 引入条目明细
//result = (Integer)this.getSqlMapClientTemplate().insert("DetailsDAO.inductDetails", detailsBO);
}
catch (Exception ex)
{
try
{
conn.rollback();
}
catch (SQLException e1)
{
Debug.error(e1.toString());
}
PmInfoException.throwPmInfoException(EccExceptionComm.ERROR_LAYER_DAO, getClass().getName(), ex);
}
finally
{
BaseDAO.closeAll(null, pstmt, conn);
}
return result;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值