Получить ошибку при выполнении строки, содержащей несколько операторов SQL, но данные обновляются - PullRequest
0 голосов
/ 16 сентября 2018

Моя среда - JDK 1.6, Eclipse Indigo, JBoss 4.2.3.GA-jdk6. База данных - Microsoft SQL Server 2008 R2. Я использую JTDS JDBC Driver.

У меня есть строка, содержащая несколько операторов SQL (UPDATE, DELETE и INSERT).

String sqlString = "update ta_rule_pakt set description = 'Syed Test 1', active_flag = '1' where paktpk = '7'  update ta_rule_break_header_paky with (rowlock) set start_time = 14400, end_time = 32364, break_code =  17, break_type = 1  where pakt_ta_rule = '7' and step = 1  delete from ta_rule_break_detail_pakz with (rowlock) where paky_ta_rule_break_header = 2  insert into ta_rule_break_detail_pakz with (rowlock) (pakzpk, paky_ta_rule_break_header, pay_code)  values(14,2, 17 )    insert into ta_rule_break_detail_pakz with (rowlock) (pakzpk, paky_ta_rule_break_header, pay_code)  values(15,2, 14 )";

Я пытался выполнить это:

Connection cx = null;
Statement st = null;

cx = getConnection();
st = cx.createStatement();   // create sql statement
st.addBatch(sqlString);
int a[] = st.executeBatch();

Но int a[] = st.executeBatch(); создает исключение

java.lang.ArrayIndexOutOfBoundsException: 1

хотя операторы SQL правильно обновили данные в базе данных.

Почему я получаю сообщение об ошибке, когда SQL верны?

Полная трассировка стека исключений:

2018-09-15 22: 45: 12 618 ОШИБКА [STDERR] java.lang.ArrayIndexOutOfBoundsException: 1 2018-09-15 22: 45: 12 618 ОШИБКА [STDERR] в net.sourceforge.jtds.jdbc.JtdsStatement.executeBatch (JtdsStatement.java:935) 2018-09-15 22: 45: 12,619 ОШИБКА [STDERR] в com.mycompany.ejb.MiscellaneousBean.UpdatePayCategoryBreakPaycode (РазноеBean.java:45517)
2018-09-15 22: 45: 12,619 ОШИБКА [STDERR] в sun.reflect.NativeMethodAccessorImpl.invoke0 (собственный метод)
2018-09-15 22: 45: 12,619 ОШИБКА [STDERR] в sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
2018-09-15 22: 45: 12 620 ОШИБКА [STDERR] в sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
2018-09-15 22: 45: 12 620 ОШИБКА [STDERR] в java.lang.reflect.Method.invoke (Method.java:597)
2018-09-15 22: 45: 12,620 ОШИБКА [STDERR] в org.jboss.invocation.Invocation.performCall (Invocation.java:359)
2018-09-15 22: 45: 12,621 ОШИБКА [STDERR] в org.jboss.ejb.StatelessSessionContainer $ ContainerInterceptor.invoke (StatelessSessionContainer.java:237)
2018-09-15 22: 45: 12,621 ОШИБКА [STDERR] в org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke (CachedConnectionInterceptor.java:158)
2018-09-15 22: 45: 12,621 ОШИБКА [STDERR] в org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke (StatelessSessionInstanceInterceptor.java:169)
2018-09-15 22: 45: 12,621 ОШИБКА [STDERR] в org.jboss.ejb.plugins.CallValidationInterceptor.invoke (CallValidationInterceptor.java:63)
2018-09-15 22: 45: 12,621 ОШИБКА [STDERR] в org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext (AbstractTxInterceptor.java:121)
2018-09-15 22: 45: 12,622 ОШИБКА [STDERR] в org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions (TxInterceptorCMT.java:404)
2018-09-15 22: 45: 12,622 ОШИБКА [STDERR] в org.jboss.ejb.plugins.TxInterceptorCMT.invoke (TxInterceptorCMT.java:181)
2018-09-15 22: 45: 12,622 ОШИБКА [STDERR] в org.jboss.ejb.plugins.SecurityInterceptor.invoke (SecurityInterceptor.java:168)
2018-09-15 22: 45: 12,622 ОШИБКА [STDERR] в org.jboss.ejb.plugins.LogInterceptor.invoke (LogInterceptor.java:205)
2018-09-15 22: 45: 12,622 ОШИБКА [STDERR] в org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke (ProxyFactoryFinderInterceptor.java:138)
2018-09-15 22: 45: 12,622 ОШИБКА [STDERR] в org.jboss.ejb.SessionContainer.internalInvoke (SessionContainer.java:648)
2018-09-15 22: 45: 12,623 ОШИБКА [STDERR] в org.jboss.ejb.Container.invoke (Container.java:960)
2018-09-15 22: 45: 12,623 ОШИБКА [СТДЕРР] в sun.reflect.GeneratedMethodAccessor103.invoke (неизвестный источник)
2018-09-15 22: 45: 12,623 ОШИБКА [STDERR] в sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
2018-09-15 22: 45: 12,623 ОШИБКА [STDERR] в java.lang.reflect.Method.invoke (Method.java:597)
2018-09-15 22: 45: 12,623 ОШИБКА [СТДЕРР] в org.jboss.mx.interceptor.ReflectedDispatcher.invoke (ReflectedDispatcher.java:155)
2018-09-15 22: 45: 12,623 ОШИБКА [STDERR] в org.jboss.mx.server.Invocation.dispatch (Invocation.java:94)
2018-09-1522: 45: 12,624 ОШИБКА [СТДЕРР] в org.jboss.mx.server.Invocation.invoke (Invocation.java:86)
2018-09-15 22: 45: 12,624 ОШИБКА [СТДЕРР] в org.jboss.mx.server.AbstractMBeanInvoker.invoke (AbstractMBeanInvoker.java:264)
2018-09-15 22: 45: 12,624 ОШИБКА [STDERR] в org.jboss.mx.server.MBeanServerImpl.invoke (MBeanServerImpl.java:659)
2018-09-15 22: 45: 12,624 ОШИБКА [STDERR] в org.jboss.invocation.local.LocalInvoker $ MBeanServerAction.invoke (LocalInvoker.java:169)
2018-09-15 22: 45: 12,624 ОШИБКА [STDERR] в org.jboss.invocation.local.LocalInvoker.invoke (LocalInvoker.java:118)
2018-09-15 22: 45: 12,624 ОШИБКА [STDERR] в org.jboss.invocation.InvokerInterceptor.invokeLocal (InvokerInterceptor.java:209)
2018-09-15 22: 45: 12,624 ОШИБКА [STDERR] в org.jboss.invocation.InvokerInterceptor.invoke (InvokerInterceptor.java:195)
2018-09-15 22: 45: 12,625 ОШИБКА [STDERR] в org.jboss.proxy.TransactionInterceptor.invoke (TransactionInterceptor.java:61)
2018-09-15 22: 45: 12,625 ОШИБКА [STDERR] в org.jboss.proxy.SecurityInterceptor.invoke (SecurityInterceptor.java:70)
2018-09-15 22: 45: 12,625 ОШИБКА [STDERR] в org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke (StatelessSessionInterceptor.java:112)
2018-09-15 22: 45: 12,625 ОШИБКА [STDERR] в org.jboss.proxy.ClientContainer.invoke (ClientContainer.java:100)
2018-09-15 22: 45: 12,625 ОШИБКА [STDERR] в $ Proxy148.UpdatePayCategoryBreakPaycode (неизвестный источник)
2018-09-15 22: 45: 12,625 ОШИБКА [STDERR] в org.apache.jsp.TARules_005fPayCategoryBreakPaycodeSelectionUpdate_jsp._jspService (TARules_005fPayCategoryBreakPaycodeSelectionUpdate_jsp.java:195)
2018-09-15 22: 45: 12,626 ОШИБКА [STDERR] в org.apache.jasper.runtime.HttpJspBase.service (HttpJspBase.java:70)
2018-09-15 22: 45: 12,626 ОШИБКА [STDERR] в javax.servlet.http.HttpServlet.service (HttpServlet.java:803)
2018-09-15 22: 45: 12,626 ОШИБКА [STDERR] в org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:370)
2018-09-15 22: 45: 12,626 ОШИБКА [STDERR] в org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:336)
2018-09-15 22: 45: 12,626 ОШИБКА [STDERR] в org.apache.jasper.servlet.JspServlet.service (JspServlet.java:265)
2018-09-15 22: 45: 12,626 ОШИБКА [STDERR] в javax.servlet.http.HttpServlet.service (HttpServlet.java:803)
2018-09-15 22: 45: 12,627 ОШИБКА [STDERR] в org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:290)
2018-09-15 22: 45: 12,627 ОШИБКА [STDERR] в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:206)
2018-09-15 22: 45: 12,627 ОШИБКА [STDERR] в org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter (SeamFilter.java:83)
2018-09-15 22: 45: 12,627 ОШИБКА [STDERR] в org.jboss.seam.web.MultipartFilter.doFilter (MultipartFilter.java:85)
2018-09-15 22: 45: 12,627 ОШИБКА [STDERR] в org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter (SeamFilter.java:69)
2018-09-15 22: 45: 12,627 ОШИБКА [STDERR] в org.jboss.seam.web.ExceptionFilter.doFilter (ExceptionFilter.java:64)
2018-09-15 22: 45: 12,627 ОШИБКА [STDERR] в org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter (SeamFilter.java:69)
2018-09-15 22: 45: 12,627 ОШИБКА [STDERR] в org.jboss.seam.web.RedirectFilter.doFilter (RedirectFilter.java:44)
2018-09-15 22: 45: 12,628 ОШИБКА [STDERR] в org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter (SeamFilter.java:69)
2018-09-15 22: 45: 12,628 ОШИБКА [STDERR] в org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter (BaseXMLFilter.java:206)
2018-09-15 22: 45: 12,628 ОШИБКА [STDERR] в org.ajax4jsf.webapp.BaseFilter.handleRequest (BaseFilter.java:290)
2018-09-15 22: 45: 12,628 ОШИБКА [STDERR] вorg.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest (BaseFilter.java:388)
2018-09-15 22: 45: 12,628 ОШИБКА [STDERR] в org.ajax4jsf.webapp.BaseFilter.doFilter (BaseFilter.java:515)
2018-09-15 22: 45: 12,628 ОШИБКА [STDERR] в org.jboss.seam.web.Ajax4jsfFilter.doFilter (Ajax4jsfFilter.java:60)
2018-09-15 22: 45: 12,628 ОШИБКА [STDERR] в org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter (SeamFilter.java:69)
2018-09-15 22: 45: 12,628 ОШИБКА [STDERR] в org.jboss.seam.web.LoggingFilter.doFilter (LoggingFilter.java:58)
2018-09-15 22: 45: 12,629 ОШИБКА [STDERR] в org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter (SeamFilter.java:69)
2018-09-15 22: 45: 12,629 ОШИБКА [STDERR] в org.jboss.seam.debug.hot.HotDeployFilter.doFilter (HotDeployFilter.java:68)
2018-09-15 22: 45: 12,629 ОШИБКА [STDERR] в org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter (SeamFilter.java:69)
2018-09-15 22: 45: 12,629 ОШИБКА [STDERR] в org.jboss.seam.servlet.SeamFilter.doFilter (SeamFilter.java:158)
2018-09-15 22: 45: 12,629 ОШИБКА [STDERR] в org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:235)
2018-09-15 22: 45: 12,629 ОШИБКА [STDERR] в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:206)
2018-09-15 22: 45: 12,629 ОШИБКА [STDERR] в com.mycompany.base.filter.BaseFilter.doFilter (BaseFilter.java:81)
2018-09-15 22: 45: 12,629 ОШИБКА [STDERR] в org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:235)
2018-09-15 22: 45: 12 630 ОШИБКА [STDERR] в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:206)
2018-09-15 22: 45: 12 630 ОШИБКА [STDERR] в org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter (ReplyHeaderFilter.java:96)
2018-09-15 22: 45: 12 630 ОШИБКА [STDERR] в org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:235)
2018-09-15 22: 45: 12 630 ОШИБКА [STDERR] в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:206)
2018-09-15 22: 45: 12 630 ОШИБКА [STDERR] в org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java:230)
2018-09-15 22: 45: 12 630 ОШИБКА [STDERR] в org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java:175)
2018-09-15 22: 45: 12 630 ОШИБКА [STDERR] в org.jboss.web.tomcat.security.SecurityAssociationValve.invoke (SecurityAssociationValve.java:182)
2018-09-15 22: 45: 12 630 ОШИБКА [STDERR] в org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java:432)
2018-09-15 22: 45: 12,631 ОШИБКА [STDERR] в org.jboss.web.tomcat.security.JaccContextValve.invoke (JaccContextValve.java:84)
2018-09-15 22: 45: 12,631 ОШИБКА [STDERR] в org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java:127)
2018-09-15 22: 45: 12,631 ОШИБКА [STDERR] в org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
2018-09-15 22: 45: 12,631 ОШИБКА [STDERR] в org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke (CachedConnectionValve.java:157)
2018-09-15 22: 45: 12,631 ОШИБКА [STDERR] в org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java:109)
2018-09-15 22: 45: 12,631 ОШИБКА [STDERR] в org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java:262)
2018-09-15 22: 45: 12,632 ОШИБКА [STDERR] в org.apache.coyote.http11.Http11Processor.process (Http11Processor.java:844)
2018-09-15 22: 45: 12,632 ОШИБКА [STDERR] в org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process (Http11Protocol.java:583)
2018-09-15 22: 45: 12,632 ОШИБКА [STDERR] в org.apache.tomcat.util.net.JIoEndpoint $ Worker.run (JIoEndpoint.java:446)
2018-09-15 22: 45: 12,632ОШИБКА [STDERR] на java.lang.Thread.run (Thread.java:662)

com.mycompany - только мой код в приведенной выше трассировке

1 Ответ

0 голосов
/ 16 сентября 2018

Вы пытались разбить вызовы на несколько операторов, чтобы попытаться определить, какая команда выдает исключение? Также странно, что вы не разделяете каждую инструкцию точкой с запятой.

    cx = getConnection();
    st = cx.createStatement();   // create sql statement
    String stmt1 = "update ta_rule_pakt set description = 'Syed Test 1', active_flag = '1' where paktpk = '7'";
    String stmt2 = "update ta_rule_break_header_paky with (rowlock) set start_time = 14400, end_time = 32364, break_code =  17, break_type = 1  where pakt_ta_rule = '7' and step = 1";
    String stmt3 = "delete from ta_rule_break_detail_pakz with (rowlock) where paky_ta_rule_break_header = 2";
    String stmt4 = "insert into ta_rule_break_detail_pakz with (rowlock) (pakzpk, paky_ta_rule_break_header, pay_code)  values(14,2, 17 )";
    String stmt5 = "insert into ta_rule_break_detail_pakz with (rowlock) (pakzpk, paky_ta_rule_break_header, pay_code)  values(15,2, 14 )";
    st.execute(stmt1);
    st.execute(stmt2);
    st.execute(stmt3);
    st.execute(stmt4);
    st.execute(stmt5);
...