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

给你一囗甜甜゛ 提交于 2019-12-04 03:36:22

问题


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());

Its giving me the following exception :

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

The myObjects is an ArrayList of the following POJO:

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

    private int age;

    ...

    // Accessors etc..

}

The T_PARAM_ARRAY on the database looks as follows :

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

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

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.


回答1:


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.



来源:https://stackoverflow.com/questions/4268093/how-can-i-prevent-this-exception-java-sql-sqlexception-fail-to-convert-to-inte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!