JDBC - Oracle ArrayIndexOutOfBoundsException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/277744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:37:15  来源:igfitidea点击:

JDBC - Oracle ArrayIndexOutOfBoundsException

oraclejdbcjboss

提问by lostinbytes

I'm getting an Exception while trying to insert a row in oracle table. I'm using ojdbc5.jar for oracle 11 this is the sql i'm trying

尝试在 oracle 表中插入一行时出现异常。我将 ojdbc5.jar 用于 oracle 11 这是我正在尝试的 sql

INSERT INTO rule_definitions(RULE_DEFINITION_SYS,rule_definition_type,
rule_name,rule_text,rule_comment,rule_message,rule_condition,rule_active,
rule_type,current_value,last_modified_by,last_modified_dttm,
rule_category_sys,recheck_unit,recheck_period,trackable)
VALUES(RULE_DEFINITIONS_SEQ.NEXTVAL,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)

and i get following Exception. Any help will be appreciated.

我得到以下异常。任何帮助将不胜感激。

java.ljava.lang.ArrayIndexOutOfBoundsException: 15
at oracle.jdbc.driver.OracleSql.computeBasicInfo(OracleSql.java:950)
    at oracle.jdbc.driver.OracleSql.getSqlKind(OracleSql.java:623)
    at oracle.jdbc.driver.OraclePreparedStatement.(OraclePreparedStatement.java:1212)
    at oracle.jdbc.driver.T4CPreparedStatement.(T4CPreparedStatement.java:28)
    at oracle.jdbc.driver.T4CDriverExtension.allocatePreparedStatement(T4CDriverExtension.java:68)
    at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:3059)
    at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:2961)
    at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:5874)
    at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:232)
    at com.gehcit.platform.cds.common.util.db.DBWrapper.executeInsertOracleReturnPK(DBWrapper.java:605)

回答by Raimonds Simanovskis

In Oracle Metalink (Oracle's support site - Note ID 736273.1) I found that this is a bug in JDBC adapter (version 10.2.0.0.0 to 11.1.0.7.0) that when you call preparedStatement with more than 7 positional parameters then JDBC will throw this error.

在 Oracle Metalink(Oracle 的支持站点 - 注释 ID 736273.1)中,我发现这是 JDBC 适配器(版本 10.2.0.0.0 到 11.1.0.7.0)中的一个错误,当您使用超过 7 个位置参数调用 PreparedStatement 时,JDBC 将抛出这个错误。

If you have access to Oracle Metalink then one option is to go there and download mentioned patch.

如果您可以访问 Oracle Metalink,那么一种选择是去那里下载提到的补丁。

The other solution is workaround - use named parameters instead of positional parameters:

另一个解决方案是解决方法 - 使用命名参数而不是位置参数:

INSERT INTO rule_definitions(RULE_DEFINITION_SYS,rule_definition_type,
rule_name,rule_text,rule_comment,rule_message,rule_condition,rule_active,
rule_type,current_value,last_modified_by,last_modified_dttm,
rule_category_sys,recheck_unit,recheck_period,trackable)
VALUES(RULE_DEFINITIONS_SEQ.NEXTVAL,:rule_definition_type,
:rule_name,:rule_text,:rule_comment,:rule_message,:rule_condition,:rule_active,
:rule_type,:current_value,:last_modified_by,:last_modified_dttm,
:rule_category_sys,:recheck_unit,:recheck_period,:trackable)

and then use

然后使用

preparedStatement.setStringAtName("rule_definition_type", ...)

etc. to set named bind variables for this query.

等等来为此查询设置命名绑定变量。

回答by Siva Anand

i am using mybatis + oracle + spring + maven. Same error "arrayindexoutofboundsexception", if having 8 (or) above parameters.

我正在使用 mybatis + oracle + spring + maven。如果有 8 个(或)以上参数,则出现相同的错误“arrayindexoutofboundsexception”。

In pom changed version ojdbc6 to ojdbc14,

在 pom 中将版本 ojdbc6 更改为 ojdbc14,

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc14</artifactId>
        <version>10.2.0.3.0</version>
    </dependency>

It worked.

有效。

回答by Kirsten

When you don't have access to the oracle.jdbc.PreparedStatement class (and are forced to use java.sql.PreparedStatement, which does not support the methods #setXXXAtName()), the proposed solution to use named parameters is not an option.

当您无权访问 oracle.jdbc.PreparedStatement 类(并且被迫使用 java.sql.PreparedStatement,它不支持方法 #setXXXAtName())时,建议的使用命名参数的解决方案不是一个选项.

I've used the PreparedStatement and GeneratedKeyHolder approach for the mandatory values to be passed (luckily less than 7), and used the generated primary key returned to issue a simple SQL update for the remaining values.

我已经使用 PreparedStatement 和 GeneratedKeyHolder 方法来传递强制值(幸运的是小于 7),并使用返回的生成主键为剩余值发出简单的 SQL 更新。

回答by madlep

Without seeing the code, the only thing I can think of is to check that each connection is being accessed in a thread safe manner. The Oracle drivers are usually pretty solid. The only time I've seen weird internal errors like that is when you've got more than one thread accessing the same connection instance and doing weird stuff with it. They aren't thread safe, and should be kept to one per thread.

没有看到代码,我唯一能想到的就是检查每个连接是否以线程安全的方式被访问。Oracle 驱动程序通常非常可靠。我唯一一次看到像这样奇怪的内部错误是当你有多个线程访问同一个连接实例并用它做奇怪的事情时。它们不是线程安全的,每个线程应该保持一个。

回答by Arne Burmeister

You create a prepared statement with 15 placeholders, if i understand correct. So you need to pass an array with 15 parameter values to the call. Maybe you missed one or added a surplus one?

如果我理解正确,您可以创建一个带有 15 个占位符的准备好的语句。因此,您需要将具有 15 个参数值的数组传递给调用。也许您错过了一个或添加了多余的一个?

回答by Elie

Looks like you're passing in the wrong number of parameters. You should be passing in 15, but you're either sending 16 or 14.

看起来您传入了错误数量的参数。您应该传入 15,但您发送的是 16 或 14。

回答by Colin Pickard

Yeah unless my mouse-cursor-counting is off, you're trying to insert 16 values into 15 columns.

是的,除非我的鼠标光标计数关闭,否则您正在尝试将 16 个值插入 15 列。

Try the same thing SQLPlus*, you should get ORA-00913: too many values

尝试同样的事情 SQLPlus*,你应该得到 ORA-00913: too many values