oracle 我怎样才能防止这个异常?java.sql.SQLException:无法转换为内部表示:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4268093/
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-18 22:01:58  来源:igfitidea点击:

How can I prevent this exception? java.sql.SQLException: Fail to convert to internal representation:

javaoraclesqlexception

提问by Jimmy

My code is throwing the above exception on the following line (line 2 of this) :

我的代码在以下行(本行的第 2 行)抛出上述异常:

final ArrayDescriptor tParamArrayDescriptor = ArrayDescriptor.createDescriptor("MY_SYSTEM.T_PARAM_ARRAY", databaseHandler.getConnection());
final ARRAY oracleArray = new ARRAY(tParamArrayDescriptor, databaseHandler.getConnection(), myObjects.toArray());

Its giving me the following exception :

它给了我以下例外:

java.sql.SQLException: Fail to convert to internal representation: 

The myObjectsis an ArrayList of the following POJO:

myObjects是以下POJO的ArrayList:

public class MyObject
{
    private String name;
    private String surname;

    private int age;

    ...

    // Accessors etc..

}

The T_PARAM_ARRAYon the database looks as follows :

T_PARAM_ARRAY数据库上看起来如下:

create or replace
TYPE               T_PARAM_ARRAY AS OBJECT (NAME VARCHAR2(50), SURNAME VARCHAR2(50), AGE NUMBER(1));

After some research, I believe that the data type mapping between my POJO and the database type don't match up correctly. I'm reasonably confident that String is matching onto VARCHAR2 ok, but I think there is an issue converting the intto a NUMBER.

经过一番研究,我认为我的 POJO 和数据库类型之间的数据类型映射不正确。我有理由相信,字符串匹配是在VARCHAR2确定,但我认为这是一个问题转换intNUMBER

I've tried using BigDecimal, but that didn't improve the situation.

我试过使用 BigDecimal,但这并没有改善情况。

Any suggestions?

有什么建议?

EDIT: According to the Oracle documentation: Where intArray is an oracle.sql.ARRAY, corresponding to a VARRAY of type NUMBER. The values array contains an array of elements of type java.math.BigDecimal, because the SQL NUMBER datatype maps to Java BigDecimal by default, according to the Oracle JDBC drivers.

编辑:根据Oracle 文档Where intArray is an oracle.sql.ARRAY, corresponding to a VARRAY of type NUMBER. The values array contains an array of elements of type java.math.BigDecimal, because the SQL NUMBER datatype maps to Java BigDecimal by default, according to the Oracle JDBC drivers.

采纳答案by Vincent Malgrat

I think you need to build the array yourself, see this question "How to call oracle stored procedure which include user-defined type in java?"for a working example.

我认为您需要自己构建数组,请参阅这个问题“如何在java中调用包含用户定义类型的oracle存储过程?” 对于一个工作示例。