'innerXml' 是一个带有大量 xml 标签的 xml 文件。我正在尝试获取标签值并将它们转储到数据库表中。
我已经尝试过下面的代码,它工作正常。
innerXml.Row.each { Row ->
sql.execute("INSERT INTO tab1(col1,col2) VALUES (${Row.Column0.text()},${Row.Column1.text()} )")
但由于 xml 标签数量巨大,逐一插入记录会导致性能问题。正如专家建议的那样,我尝试使用 withBatch 来提高性能。请找到我尝试使用 withBatch 的以下代码:
sql.withBatch(386, """ insert into tab1(col1,col2) values (?, ?) """) { ps -> innerXml.Row.each { Row ->ps.addBatch(${Row.Column0.text()} ,${Row.Column1.text()}) }}
但我收到以下错误:
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: 38
请帮忙
提前致谢!!