但是,由于存在大量xml标签,导致性能问题逐一插入记录。正如专家建议我尝试使用withBatch来提高性能。请找到下面的代码,我尝试与批次:
sql.withBatch (386,插入到tab1(col1,col2)值(?,?)){ps-> innerXml.Row.each {Row - > ps.addBatch($ {Row.Column0.text()},$ {Row.Column1.text()})}}但是我得到的错误是:
groovy。 lang.MissingMethodException:没有方法签名:Script41。$()适用于参数类型:(Script41 $ _run_closure2_closure3_closure4)values:[Script41 $ _run_closure2_closure3_closure4 @ 23724e8d]可能的解决方案:is(java.lang.Object),run(), 38行$($ b $ / code>)上的run(),any(),use([Ljava.lang.Object;),任何(groovy.lang.Closure)
请帮忙
在此先感谢!!
解决方案您需要做的:
// 386是一个奇数批量大小? sql.withBatch(386,'insert into tab1(col1,col2)values(?,?)'){ps - > innerXml.Row.each {row - > ps.addBatch(row.Column0.text(),row.Column1.text())} }
'innerXml' is a xml file with huge number of xml tags . I am trying fetch the tag values and dump them into database table . I have tried below code and it is working fine .
innerXml.Row.each { Row -> sql.execute("INSERT INTO tab1(col1,col2) VALUES (${Row.Column0.text()},${Row.Column1.text()} )")But as there is huge number of xml tags its causing performance issue to insert record one by one . As the experts suggested I tried using withBatch to improve performance.Please find the below code which I tried with withBatch :
sql.withBatch(386, """ insert into tab1(col1,col2) values (?, ?) """) { ps -> innerXml.Row.each { Row ->ps.addBatch(${Row.Column0.text()} ,${Row.Column1.text()}) }}But I am getting below error :
groovy.lang.MissingMethodException: No signature of method: Script41.$() is applicable for argument types: (Script41$_run_closure2_closure3_closure4) values: [Script41$_run_closure2_closure3_closure4@23724e8d] Possible solutions: is(java.lang.Object), run(), run(), any(), use([Ljava.lang.Object;), any(groovy.lang.Closure) error at line: 38Please help
Thanks in Advance!!
解决方案You need to do:
// 386 is an odd batch size? sql.withBatch(386, 'insert into tab1(col1,col2) values (?, ?)') { ps -> innerXml.Row.each { row -> ps.addBatch(row.Column0.text(), row.Column1.text()) } }
更多推荐
如何正确使用AddBatch / withBatch将XML标记值批量插入到数据库表中
发布评论