22,210
社区成员
发帖
与我相关
我的任务
分享
public int saveRecvToDB(DeliverMessage[] moMsg) {
int count = 0;
C3P0 c3p0=C3P0.getInstance();
Connection conn =c3p0.getConnection();
if (conn == null) {
return count;
}
CallableStatement cStmt = null;
try {
conn.setAutoCommit(false);
cStmt = conn.prepareCall("{ call "
+ AppConfig.getWriteRecvProcedure() + "(?,?,?,?,?,?) }");
for (int i = 0; i < moMsg.length; i++) {
if(moMsg[i] == null)
continue;
if(moMsg[i].CONTENT_TYPE==2){
if(moMsg[i].ECODE==0){
moMsg[i].ECODE=0;
}else if(moMsg[i].ECODE==1||moMsg[i].ECODE==20||moMsg[i].ECODE==24
||moMsg[i].ECODE==29){
moMsg[i].ECODE=2;
}else{
moMsg[i].ECODE=1;
}
}
cStmt.setString(1, moMsg[i].SRCMOBILE);
cStmt.setInt(2, moMsg[i].CONTENT_TYPE);
cStmt.setString(3, moMsg[i].CONTENT);
cStmt.setString(4, moMsg[i].SENDID);
cStmt.setInt(5, moMsg[i].ECODE);
cStmt.setString(6, AppConfig.getIdentity()+moMsg[i].LONGID);
cStmt.addBatch();
count++;
}
cStmt.executeBatch();
conn.commit();
conn.setAutoCommit(true);
} catch (SQLException e) {
AppLoger.info("[CMPP-GW DBOperator]Exception Save mo Failed!!!"
+ e.getMessage());
try {
conn.rollback();
} catch (SQLException e1) {
}
return 0;
} finally {
close(null, cStmt);
if (null != conn) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return count;
}
PROCEDURE [dbo].[qdpolice_writeRecv]
@phone varchar(12),
@contentType int, --上行0内容,4状态报告
@msg varchar(500),
@sendID varchar(50),
@status int,--ecode
@longid varchar(20)
AS
BEGIN
SET NOCOUNT ON;
if @contentType = 0
begin
insert into MODB
(REVETIME
,MSGCONTENT
,PHONE
,SpNUMBER)
values
(getdate()
,@msg
,@phone
,@longid);
end
else
begin
insert into ReportStatusDB
(MSGID
,PHONE
,MSGSTATUS)
values
(@sendID
,@phone
,@status);
end
--select @v_guid
END