一、存储过程创建脚本
CREATE PROCEDURE ASSET_COMPUTERUP_HISTORY
@COMPUTERASSETID NUMERIC,
@COMPUTERTYPE varchar(50),
@COMPUTERNUM VARCHAR(16),
@BRANDMODEL VARCHAR(30),
--暂时未使用,调拨时使用@DID NUMERIC,
@SUPERINT VARCHAR(12),
@STARTUSEDAT DATETIME,
--暂时未使用,保留字段 @IPTDAT DATETIME,
@IPADDRESS VARCHAR(50),
@MACADDRESS VARCHAR(50),
@CPUGHZSIZE VARCHAR(50),
@MEMBERYSIZE VARCHAR(50),
@DISKSIZE VARCHAR(50),
@SWITCHADDRESS VARCHAR(50),
@PORTNUM VARCHAR(50),
--暂时未使用,保留字段 @OSPERSON VARCHAR(50),
@BINDFLAG CHAR(1),
@INTERNETFLAG CHAR(1),
@REMARK VARCHAR(255)
--暂时未使用,保留字段@STATUS CHAR(1)
AS
BEGIN
SET NOCOUNT ON;
begin transaction;
INSERT INTO COMPUTERASSETUP(COMPUTERASSETID,COMPUTERTYPE,COMPUTERNUM,BRANDMODEL,DID,SUPERINT,STARTUSEDAT,IPADDRESS,MACADDRESS,
CPUGHZSIZE,MEMBERYSIZE,DISKSIZE,SWITCHADDRESS,PORTNUM,BINDFLAG,INTERNETFLAG,REMARK,STATUS)
(SELECT COMPUTERASSETID,COMPUTERTYPE,COMPUTERNUM,BRANDMODEL,DID,SUPERINT,STARTUSEDAT,IPADDRESS,MACADDRESS,
CPUGHZSIZE,MEMBERYSIZE,DISKSIZE,SWITCHADDRESS,PORTNUM,BINDFLAG,INTERNETFLAG,REMARK,STATUS FROM COMPUTERASSET WHERE (COMPUTERASSETID=@COMPUTERASSETID));
UPDATE COMPUTERASSET SET COMPUTERTYPE=@COMPUTERTYPE,COMPUTERNUM=@COMPUTERNUM,BRANDMODEL=@BRANDMODEL,SUPERINT=@SUPERINT,STARTUSEDAT=@STARTUSEDAT,IPADDRESS=@IPADDRESS,MACADDRESS=@MACADDRESS,
CPUGHZSIZE=@CPUGHZSIZE,MEMBERYSIZE=@MEMBERYSIZE,DISKSIZE=@DISKSIZE,SWITCHADDRESS=@SWITCHADDRESS,PORTNUM=@PORTNUM,BINDFLAG=@BINDFLAG,INTERNETFLAG=@INTERNETFLAG,REMARK=@REMARK WHERE COMPUTERASSETID=@COMPUTERASSETID
if @@error<>0 or @@rowcount = 0
begin
print 'rollback';
rollback transaction;
end
else
begin
print 'commit';
COMMIT transaction ;
END
End
GO
2、dao实现类如下:
public void updateComputerAsset(final ComputerAsset computer) {
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws SQLException {
Connection con = session.connection();
//调用发票入库存储过程
CallableStatement cs = con
.prepareCall("{call ASSET_COMPUTERUP_HISTORY(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
//设置电脑资产主键标识
cs.setLong(1, computer.getComputerassetid());
//设置电脑资产类型
cs.setString(2, computer.getComputertype());
//设置电脑资产编号
cs.setString(3, computer.getComputernum());
//设置电脑资产规格型号
cs.setString(4, computer.getBrandmodel());
//设置电脑资产部门DID
//cs.setLong(4, computer.getDepartment().getId());
//设置电脑资产责任人
cs.setString(5, computer.getSuperint());
//设置电脑资产开始使用日期
cs.setTimestamp(6, computer.getStartusedat());
//设置电脑资产IP地址
cs.setString(7, computer.getIpaddress());
//设置电脑资产Mac地址
cs.setString(8, computer.getMacaddress());
//设置电脑资产Cpu大小
cs.setString(9, computer.getCpughzsize());
//设置电脑资产内存大小
cs.setString(10, computer.getMemberysize());
//设置磁盘大小
cs.setString(11, computer.getDisksize());
//设置交换机IP地址
cs.setString(12,computer.getSwitchaddress());
cs.setString(13,computer.getPortnum());
cs.setString(14,computer.getBindflag());
cs.setString(15,computer.getInternetflag());
cs.setString(16,computer.getRemark());
cs.execute();
cs.close();
return null;
}
});
}