从一天起,我尝试使用批处理插入大量数据(每行大约120万行10列)。以下是我的代码。
PreparedStatement destStmt = destConn.prepareStatement(insertQuery);
while(somedata){
for(i=0;i<columnList.size();i++){
//setting values of aquery
}
destStmt.addBatch();
if (++count % batchSize == 0) {
destStmt.executeBatch();
}
}
destStmt.executeBatch();
这里
以下提到的例外情况。
java.sql.BatchUpdateException: invalid batch command
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:571)
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:626)
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:665)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3892)
at in.net.usit.dbu.web.query.QueryDispatcher.executeInsert(QueryDispatcher.java:97)
at in.net.usit.dbu.web.query.QueryModel.executeInsert(QueryModel.java:13)
at in.net.usit.dbu.web.query.QueryViewModel.executeQuery(QueryViewModel.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.zkoss.bind.impl.ParamCall.call(ParamCall.java:111)
at org.zkoss.bind.impl.BinderImpl.doExecute(BinderImpl.java:1745)
at org.zkoss.bind.impl.BinderImpl.doCommand(BinderImpl.java:1506)
at org.zkoss.bind.impl.BinderImpl.access$1500(BinderImpl.java:107)
at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent0(BinderImpl.java:1375)
at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent(BinderImpl.java:1327)
at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2743)
at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2714)
at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2655)
at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1721)
at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1506)
at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1216)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:601)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:483)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:492)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Jan 03, 2017 10:45:04 AM org.zkoss.bind.impl.BinderImpl$CommandEventListener onEvent:1329
SEVERE: java.sql.BatchUpdateException: invalid batch command
org.zkoss.zk.ui.UiException: java.sql.BatchUpdateException: invalid batch command
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.zkoss.lang.Classes.newInstance(Classes.java:73)
at org.zkoss.lang.Exceptions.wrap(Exceptions.java:161)
at org.zkoss.zk.ui.UiException$Aide.wrap(UiException.java:44)
at org.zkoss.bind.impl.ParamCall.call(ParamCall.java:118)
at org.zkoss.bind.impl.BinderImpl.doExecute(BinderImpl.java:1745)
at org.zkoss.bind.impl.BinderImpl.doCommand(BinderImpl.java:1506)
at org.zkoss.bind.impl.BinderImpl.access$1500(BinderImpl.java:107)
at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent0(BinderImpl.java:1375)
at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent(BinderImpl.java:1327)
at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2743)
at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2714)
at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2655)
at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1721)
at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1506)
at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1216)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:601)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:483)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:492)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.BatchUpdateException: invalid batch command
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:571)
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:626)
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:665)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3892)
at in.net.usit.dbu.web.query.QueryDispatcher.executeInsert(QueryDispatcher.java:97)
at in.net.usit.dbu.web.query.QueryModel.executeInsert(QueryModel.java:13)
at in.net.usit.dbu.web.query.QueryViewModel.executeQuery(QueryViewModel.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.zkoss.bind.impl.ParamCall.call(ParamCall.java:111)
... 38 more
Jan 03, 2017 10:45:04 AM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1363
SEVERE: >>org.zkoss.zk.ui.UiException: java.sql.BatchUpdateException: invalid batch command
[SQL: 17080, null]
>>java.sql.BatchUpdateException: invalid batch command
>> at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:571)
>> at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:626)
>> at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:665)
>> at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3892)
>> at in.net.usit.dbu.web.query.QueryDispatcher.executeInsert(QueryDispatcher.java:97)
>> at in.net.usit.dbu.web.query.QueryModel.executeInsert(QueryModel.java:13)
>> at in.net.usit.dbu.web.query.QueryViewModel.executeQuery(QueryViewModel.java:86)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>> at java.lang.reflect.Method.invoke(Unknown Source)
>> at org.zkoss.bind.impl.ParamCall.call(ParamCall.java:111)
>> at org.zkoss.bind.impl.BinderImpl.doExecute(BinderImpl.java:1745)
>> at org.zkoss.bind.impl.BinderImpl.doCommand(BinderImpl.java:1506)
>> at org.zkoss.bind.impl.BinderImpl.access$1500(BinderImpl.java:107)
>> at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent0(BinderImpl.java:1375)
>> at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent(BinderImpl.java:1327)
>> at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2743)
>> at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2714)
>> at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2655)
>> at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
>> at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1721)
>> at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1506)
>> at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1216)
>> at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:601)
>> at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:483)
>> at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:492)
>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
>> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
>> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
>> at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
>> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
>> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
>> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
>> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
>> at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
>> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
>> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
>> at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
>> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
>> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
>> at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
>> at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
>> at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
>> at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
>> at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
>> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
>> at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
>> at java.lang.Thread.run(Unknown)
帮我解决这个问题。
答案 0 :(得分:0)
如果绑定类型发生更改,则驱动程序可以抛出此异常。请确保使用相同的setter方法跨批处理行设置绑定数据。