Work bug: for loop inside to create objects and create objects out of the for loop

The main role of writing this blog is to give himself up up memory, after low-level errors like this better not be repeated.

Look at the error log:

1 2019-12-25 18:12:58.197 DEBUG 12332 --- [io-8080-exec-10] com.sinosoft.utility.SQLString           : 进入更新后的InsPart
2 2019-12-25 18:12:58.197 DEBUG 12332 --- [io-8080-exec-10] com.sinosoft.utility.SQLString           : mSql: insert into LPEdorItem ( EdorAcceptNo,EdorNo,EdorCode,PolicyNo,CustomerID,EdorState,ChangeMoney,BillMoney,EdorValiDate,Creator,Operator,MakeDate,MakeTime,ModifyDate,ModifyTime ) values ( 'MGU201912461201912358','EN20191225026','RE','MGU201912461','000000','10',1000.0,0.0,'2019-12-25','001','001','2019-12-25','18:12:41','2019-12-25','18:12:41' )
3 2019-12-25 18:12:58.246 DEBUG 12332 --- [io-8080-exec-10] com.sinosoft.utility.SQLString           : mSql: delete from LPDebitNote where EdorNo='EN20191225026' and DebitNoteNo='DN0000000234'
4 2019-12-25 18:12:58.246 DEBUG 12332 --- [io-8080-exec-10] com.sinosoft.utility.SQLString           : mSql: delete from LPDebitNote where EdorNo='EN20191225026' and DebitNoteNo='DN0000000234'
5 2019-12-25 18:12:58.372 DEBUG 12332 --- [io-8080-exec-10] com.sinosoft.utility.SQLString           : 进入更新后的InsPart
6 2019-12-25 18:12:58.372 DEBUG 12332 --- [io-8080-exec-10] com.sinosoft.utility.SQLString           : mSql: insert into LPDebitNote ( EdorNo,EdorCode,DebitNoteNo,DNTAmount,DebitNoteTitle,PaidAmnt,PaidCurr,PayDate,Status,VerificationAnt,DebitNoteMode,SubInsurerId,BankAccId,RiskCode,Creator,Operator,MakeDate,MakeTime,ModifyDate,ModifyTime ) values ( 'EN20191225026','RE','DN0000000234',1000.0,'22',1000.0,'01','2020-01-24','01',0.0,'04','ZCB-003-111','888888','X151','001','001','2019-12-25','18:12:41','2019-12-25','18:12:41' )
7 2019-12-25 18:12:58.372 DEBUG 12332 --- [io-8080-exec-10] com.sinosoft.utility.SQLString           : 进入更新后的InsPart
8 2019-12-25 18:12:58.372 DEBUG 12332 --- [io-8080-exec-10] com.sinosoft.utility.SQLString           : mSql: insert into LPDebitNote ( EdorNo,EdorCode,DebitNoteNo,DNTAmount,DebitNoteTitle,PaidAmnt,PaidCurr,PayDate,Status,VerificationAnt,DebitNoteMode,SubInsurerId,BankAccId,RiskCode,Creator,Operator,MakeDate,MakeTime,ModifyDate,ModifyTime )
 values ( 'EN20191225026','RE','DN0000000234',1000.0,'22',1000.0,'01','2020-01-24','01',0.0,'04','ZCB-003-111','888888','X151','001','001','2019-12-25','18:12:41','2019-12-25','18:12:41' )

From the top to see the error log, the error is already evident in the implementation report the conflict to the primary key when inserting data LPDebitNote table. Seen from the SQL statement, it is indeed the case.

In a look at the code before writing your own:

In fact, there is a line at the top: LPDebitNoteSchema tLPDebitNoteSchema = new LPDebitNoteSchema ();

 

 Now it is not difficult to see because of the addition of two identical objects to mlpdebitnotese tLPDebitNoteSchema collection, but the objects are the last cycle.

After the correction of code:

. 1              SQLwithBindVariables sqlbv = new new SQLwithBindVariables ();
 2              String TSQL = "PolicyNo the SELECT * = the FROM LCDebitNoteDet the WHERE 'PolicyNo??'" ;
 . 3              sqlbv = new new SQLwithBindVariables ();
 . 4              sqlbv.sql (TSQL);
 . 5              sqlbv.put ( " PolicyNo " , mLPEdorAppSchema.getPolicyNo ());
 . 6              tLCDebitNoteDetSet = tLCDebitNoteDetDB.executeQuery (sqlbv);
 . 7              // in a table inside LCDEBITNOTEDET can have a plurality of policy number DEBITNOTENO 
. 8              IF ! (tLCDebitNoteDetSet = null && tLCDebitNoteDetSet.size ()> 0 ) {
 9                 for (int i = 1; i <=tLCDebitNoteDetSet.size() ; i++) {
10                     LPDebitNoteSchema tLPDebitNoteSchema = new LPDebitNoteSchema();
11                     SQLwithBindVariables sqlbv1 = new SQLwithBindVariables();
12                     String tSql1 = "SELECT * FROM LCDebitNote WHERE DebitNoteNo='?DebitNoteNo?' ";
13                     sqlbv1 = new SQLwithBindVariables();
14                     sqlbv1.sql(tSql1);
15                     sqlbv1.put("DebitNoteNo", tLCDebitNoteDetSet.get(i).getDebitNoteNo());
16                      tLCDebitNoteSet = tLCDebitNoteDB.executeQuery (sqlbv1);
 . 17                      IF (! TLCDebitNoteSet = null && tLCDebitNoteSet.size ()> 0 ) {
 18 is                          tLCDebitNoteSchema tLCDebitNoteSet.get = (. 1 );
 . 19                          the this .mReflections.transFields (tLPDebitNoteSchema, tLCDebitNoteSchema);
 20 is                          tLPDebitNoteSchema.setEdorNo (mEdorNo);
 21                          tLPDebitNoteSchema.setEdorCode (mLPEdorAppSchema.getEdorCode ());
 22                          //    tLPDebitNoteSchema.setSelfPayOffState ( "02"); when issued during a state of change
 23                          // tLPDebitNoteSchema.setVerificationDate(mCurrentDate);
24                         tLPDebitNoteSchema.setOperator(mG.Operator);
25                         tLPDebitNoteSchema.setMakeDate(mCurrentDate);
26                         tLPDebitNoteSchema.setMakeTime(mCurrentTime);
27                         tLPDebitNoteSchema.setModifyDate(mCurrentDate);
28                         tLPDebitNoteSchema.setModifyTime(mCurrentTime);
29                         //mMap.put(tLPDebitNoteSchema,"DELETE&INSERT");
30                     }
31                     mLPDebitNoteSet.add(tLPDebitNoteSchema);
32                 }
33                 mMap.put(mLPDebitNoteSet,"DELETE&INSERT");
34             }

This can be the perfect run, and will not report the primary key conflict.

Guess you like

Origin www.cnblogs.com/dongyaotou/p/12100487.html