如何防止这种异常? java.sql.SQLException:无法转换为内部表示形式: [英] How can I prevent this exception? java.sql.SQLException: Fail to convert to internal representation:

查看:769
本文介绍了如何防止这种异常? java.sql.SQLException:无法转换为内部表示形式:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码在以下行(此行的第2行)上引发了上述异常:

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

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

它给了我以下例外:

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

myObjects是以下POJO的ArrayList:

The myObjects is an ArrayList of the following POJO:

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

    private int age;

    ...

    // Accessors etc..

}

数据库上的T_PARAM_ARRAY如下所示:

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

经过研究,我认为我的POJO和数据库类型之间的数据类型映射不正确.我相当有信心String可以与VARCHAR2匹配,但是我认为将int转换为NUMBER时存在问题.

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 int to a NUMBER.

我尝试使用BigDecimal,但这并不能改善情况.

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

有什么建议吗?

根据 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.

推荐答案

我认为您需要自己构建数组,请参见此问题作为一个工作示例.

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.sql.SQLException:无法转换为内部表示形式:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆