Getting Extra Record and Shouldn't

Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Getting Extra Record and Shouldn't

BBuzzard

Help!  Running the follow code which should insert just one record, but when I look at the database I see two record and I don’t understand how I created the second record.  Here’s the code:

 

                private static toDatabase(List recs) {

                               

                                println "recs.size=${recs?.size()}"

 

                                def NameIn

                                def SizeIn

                                def LastModIn

                                def HostIn

                                def AppIn

                                def EndPtIn

 

                                def NameOut

                                def SizeOut

                                def LastModOut

                                def HostOut

                                def AppOut

                                def EndPtOut

 

                                def Action

 

                                def flds

 

                                def sql

                                def result

                               

                                def count = 0

 

                               

                                try {

               

                                                recs = ["XYZ,AFH3AJ8XCCGZBPW04836,8321280,2017-11-12 16:32:45.215,DPIJ3C5FV7,JE61P2M0G,ENM99E920R2SD0R,A2P2GO3NYI5U4F4G3HU1,7305184,2017-11-12 16:32:45.215,MNF9FT5E55,L6L1J9RVS,3RYUPAQJLVKGJO1,Drop"]

                                               

                                                def cmd = "{call uspRecordBreadcrumb(?,?,?,?,?,?,?,?,?,?,?,?,?)}"

                                                result = sql.withBatch(20,cmd) { ps ->

                                                               

                                                                recs.each{ rec ->

                                                                                flds = rec.split(/,/)

                                                                               

                                                                                NameIn = "${flds[1]}".toString()

                                                                                SizeIn = "${flds[2]}".toString()

                                                                                LastModIn = "${flds[3]}".toString()

                                                                                HostIn =  "${flds[4]}".toString()

                                                                                AppIn = "${flds[5]}".toString()

                                                                                EndPtIn =  "${flds[6]}".toString()

               

                                                                                NameOut = "${flds[7]}".toString()

                                                                                SizeOut = "${flds[8]}".toString()

                                                                                LastModOut = "${flds[9]}".toString()

                                                                                HostOut =  "${flds[10]}".toString()

                                                                                AppOut = "${flds[11]}".toString()

                                                                                EndPtOut =  "${flds[12]}".toString()

               

                                                                                Action = "${flds[13]}".toString()

               

                                                                                LastModIn ?: SDF.format(0)

                                                                                LastModOut ?:  SDF.format(0)

                                                                                SizeIn ?: 0

                                                                                SizeOut ?: 0

 

                                                                                try {                       

                                                                                ps.addBatch(NameIn,SizeIn,LastModIn,AppIn,HostIn,EndPtIn,NameOut,SizeOut,LastModOut,AppOut,HostOut,EndPtOut,Action)

                                                                                                count++

                                                                                               

                                                                                } catch (BatchUpdateException bue) {

                                                                                                def updateCounts = bue.updateCounts

                                                                                                updateCounts.eachWithIndex { retval,idx ->

                                                                                                                if(retval<0) {

                                                                                                                                println "$idx. ${recs[idx]}"

                                                                                                                }

                                                                                                }

                                                                                                println "updateCounts=$updateCounts"

                                                                                }

                                                                }

                                                }

 

                                } catch (Exception ex) {

                                                ex.printStackTrace()

                                } finally {

                                                sql.close()

                                }

                }

 

 

This is what I see in the database:

 

ID            Name    Size        LastModified     EntryDateTime

147590  A_FH3AJ8XCCGZBPW04836         8321280                2017-11-12 16:32:45.217               2017-11-14 12:46:08.523

147591  A2P2GO3NYI5U4F4G3HU1           7305184                2017-11-12 16:32:45.217               2017-11-14 12:46:08.523