我正在尝试使用SqlParameterSource插入记录,而我正在执行以下行,它显示array out of bound exception
:
this.getNamedParameterJdbcTemplate().update(query, source,key,new String[]{"column"});
但是当我使用以下代码时:
this.getNamedParameterJdbcTemplate().update(query, source);
我没有得到例外。还有其他人遇到过这样的问题吗?
DEBUG 1685 DEBUG c.h.p.m.d.i.InsertCurrentDAOImpl - Starting insert method
ERROR 8550 ERROR c.h.p.m.d.i.InsertCurrentDAOImpl - 8
java.lang.ArrayIndexOutOfBoundsException: 8
at oracle.jdbc.driver.OracleSql.computeBasicInfo(OracleSql.java:950) ~[ojdbc6.jar:Oracle JDBC Driver version - "11.1.0.7.0-Production"]
at oracle.jdbc.driver.OracleSql.getSqlKind(OracleSql.java:623) ~[ojdbc6.jar:Oracle JDBC Driver version - "11.1.0.7.0-Production"]
at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:1212) ~[ojdbc6.jar:Oracle JDBC Driver version - "11.1.0.7.0-Production"]
at oracle.jdbc.driver.T4CPreparedStatement.<init>(T4CPreparedStatement.java:28) ~[ojdbc6.jar:Oracle JDBC Driver version - "11.1.0.7.0-Production"]
at oracle.jdbc.driver.T4CDriverExtension.allocatePreparedStatement(T4CDriverExtension.java:68) ~[ojdbc6.jar:Oracle JDBC Driver version - "11.1.0.7.0-Production"]
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:3140) ~[ojdbc6.jar:Oracle JDBC Driver version - "11.1.0.7.0-Production"]
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:3042) ~[ojdbc6.jar:Oracle JDBC Driver version - "11.1.0.7.0-Production"]
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:6022) ~[ojdbc6.jar:Oracle JDBC Driver version - "11.1.0.7.0-Production"]
at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:232) ~[org.springframework.jdbc-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:580) ~[org.springframework.jdbc-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:842) ~[org.springframework.jdbc-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:287) ~[org.springframework.jdbc-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at com.persistence.material.dao.impl.InsertCurrentDAOImpl.insertInventoryCurrent(InsertCurrentDAOImpl.java:50) ~[bin/:na]
at com.persistence.material.dao.impl.InsertCurrentDAOImplTest.insertMaterialInventoryCurrentTest(InsertCurrentDAOImplTest.java:61) [bin/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_13]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_13]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_13]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_13]
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) [testng.jar:6.8.1-201303300836]
at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:200) [testng.jar:6.8.1-201303300836]
at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158) [spring-test-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_13]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_13]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_13]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_13]
at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:212) [testng.jar:6.8.1-201303300836]
at org.testng.internal.Invoker.invokeMethod(Invoker.java:707) [testng.jar:6.8.1-201303300836]
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) [testng.jar:6.8.1-201303300836]
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) [testng.jar:6.8.1-201303300836]
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) [testng.jar:6.8.1-201303300836]
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) [testng.jar:6.8.1-201303300836]
at org.testng.TestRunner.privateRun(TestRunner.java:767) [testng.jar:6.8.1-201303300836]
at org.testng.TestRunner.run(TestRunner.java:617) [testng.jar:6.8.1-201303300836]
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334) [testng.jar:6.8.1-201303300836]
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329) [testng.jar:6.8.1-201303300836]
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291) [testng.jar:6.8.1-201303300836]
at org.testng.SuiteRunner.run(SuiteRunner.java:240) [testng.jar:6.8.1-201303300836]
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) [testng.jar:6.8.1-201303300836]
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) [testng.jar:6.8.1-201303300836]
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) [testng.jar:6.8.1-201303300836]
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) [testng.jar:6.8.1-201303300836]
at org.testng.TestNG.run(TestNG.java:1057) [testng.jar:6.8.1-201303300836]
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111) [testng.jar:6.8.1-201303300836]
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204) [testng.jar:6.8.1-201303300836]
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175) [testng.jar:6.8.1-201303300836]
com.exception.PersistenceException: java.lang.ArrayIndexOutOfBoundsException: 8
at com.persistence.material.dao.impl.InsertCurrentDAOImpl.insertInventoryCurrent(InsertCurrentDAOImpl.java:54)
at com.persistence.material.dao.impl.InsertCurrentDAOImplTest.insertMaterialInventoryCurrentTest(InsertCurrentDAOImplTest.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:200)
at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:212)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 8
at oracle.jdbc.driver.OracleSql.computeBasicInfo(OracleSql.java:950)
at oracle.jdbc.driver.OracleSql.getSqlKind(OracleSql.java:623)
at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:1212)
at oracle.jdbc.driver.T4CPreparedStatement.<init>(T4CPreparedStatement.java:28)
at oracle.jdbc.driver.T4CDriverExtension.allocatePreparedStatement(T4CDriverExtension.java:68)
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:3140)
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:3042)
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:6022)
at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:232)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:580)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:842)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:287)
at com.persistence.material.dao.impl.InsertCurrentDAOImpl.insertInventoryCurrent(InsertCurrentDAOImpl.java:50)
... 32 more
答案 0 :(得分:0)
将数据插入具有27列的DB表时,我遇到类似的问题。我正在使用NamedParameterJdbcTemplate类插入数据。在这方面的任何帮助都是非常有帮助的。请找到下面的代码段
SqlParameterSource parameters = new MapSqlParameterSource()
.addValue("Id", 12345678)
.addValue("packageId", info.getIrocPkgId())
.addValue("isAsgn", 1)
.addValue("startTm", info.getStartTm())
.addValue("endTm", info.getEndTm())
.addValue("type", ConstantVal.TASK)
.addValue("note", ConstantVal.ETA + ":" + info.getEta())
.addValue("fdbk", ConstantVal.EMPTY)
.addValue("sCnt", 1)
.addValue("aCd", ConstantVal.ETA)
.addValue("isAuto", 1)
.addValue("dfltStartTm", info.getStartTm())
.addValue("dfltEndTm", info.getEndTm())
.addValue("aInfo", ConstantVal.EMPTY)
.addValue("stat", ConstantVal.ACTIVE)
.addValue("cnclTask", ConstantVal.ZERO)
.addValue("asgnNbr", ConstantVal.EMPTY)
.addValue("priInd", ConstantVal.ZERO)
.addValue("ovlpMatchNbr", ConstantVal.EMPTY)
.addValue("attchIds", ConstantVal.EMPTY)
.addValue("aType", ConstantVal.EMPTY)
.addValue("lInd", ConstantVal.ZERO)
.addValue("pAsgn", ConstantVal.ZERO)
.addValue("rId", ConstantVal.EMPTY)
.addValue("bInd", ConstantVal.EMPTY)
.addValue("createDtTm", new Timestamp((new Date()).getTime()))
.addValue("updatedDtTm", ConstantVal.EMPTY);
int nb = namedParameterJdbcTemplate.update(insertRecords, parameters, keyHolder,new String[] { "ID" });
beans.xml中的SQL查询在下面给出
<bean id="insertRecords" class="java.lang.String"
scope="prototype">
<constructor-arg type="java.lang.String"
value="
INSERT
INTO
XYZ
(
ID,
PACKAGE_ID,
IS_ASGN,
START_TM,
END_TM,
TYPE,
NOTE,
FDBK,
S_CNT,
A_CD,
IS_AUTO,
DFLT_START_TM,
DFLT_END_TM,
A_INFO,
STAT,
IS_CNCL_TASK,
ASGN_NBR,
PRI_ASGN_IND,
OVLP_MATCH_NBR,
A_IDS,
ASGN_TYPE,
LOCK_IND,
P_ASGN,
R_ID,
B_IND,
CREATED_DT_TM,
UPDATED_DT_TM
)
VALUES
(
:Id,
:packageId,:isAsgn,:startTm,:endTm,:type,:note,:fdbk,:sCnt,:aCd,:isAuto,:dfltStartTm,:dfltEndTm,:aInfo,
:stat,:cnclTask,:asgnNbr,:priInd,:ovlpMatchNbr,:attchIds,:aType,:lInd,:pAsgn,:rId,
:bInd,:createDtTm,:updatedDtTm) " />
</bean>
我在插入数据时看到以下错误
java.lang.ArrayIndexOutOfBoundsException
at oracle.jdbc.driver.OracleSql.computeBasicInfo(OracleSql.java:950)
at oracle.jdbc.driver.OracleSql.getSqlKind(OracleSql.java:623)
at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:1212)
at oracle.jdbc.driver.T4CPreparedStatement.<init>(T4CPreparedStatement.java:28)
at oracle.jdbc.driver.T4CDriverExtension.allocatePreparedStatement(T4CDriverExtension.java:68)
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:3140)
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:3042)
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:6022)
at oracle.jdbc.OracleConnectionWrapper.prepareStatement(OracleConnectionWrapper.java:679)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.pmiPrepareStatement(WSJdbcConnection.java:5071)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:4946)
at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:231)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:638)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:943)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:344)