Skip to content Skip to sidebar Skip to footer

Java.sql.sqlexception: Fail To Convert To Internal Representation: While Passing Arraylist To Oracle.sql.array

Hi this is my code List listA = new ArrayList(0); String[] arrA = new String[100]; listA.add('aaa'); listA.add('bbb'); arrA[0]='aaa'; arrA[1]='bbb'; con

Solution 1:

Convert your list to array before the line

ARRAY array_to_pass1 = newARRAY(des, conn, arrA );

You can add/remove items from the list prior to this.

String[] arrA= newString[listA.size()];
arrA= listA.toArray(arrA);

Solution 2:

Try this approach

Listlist=newArrayList();
callableStatement = 
          (OracleCallableStatement)connection.prepareCall("{call yourprocedure(?)}");
            StructDescriptorstructDescriptor= 
                StructDescriptor.createDescriptor("TYPE_ARRAY", 
                                                  connection);
            STRUCT[] structs = newSTRUCT[list.size()];
            for (inti=0; i < list.size(); ++i) {

                Yourclassstr= 
                    (Yourclass)list.get(i);
                Object[] objects =

                    newObject[] { str.getProdId(), 
                                   str.getName()
                                 };
                STRUCTstruct=newSTRUCT(structDescriptor, connection, objects);
                structs[i] = struct;
            }
            ArrayDescriptorarrayDescriptor= 
                ArrayDescriptor.createDescriptor("ARRAY_MY", 
                                                 connection);

            ARRAYarray=newARRAY(arrayDescriptor, connection, structs);
            callableStatement.setArray(1, array);
            callableStatement.executeUpdate();

Solution 3:

The Oracle's document about ARRAY is incomplete, and i find it's all pass string[] array in everywhere.

So I suggest you change the ArrayList to String[] array like that:

String[] arrA = listA.toArray(newString[listA.size()]);  

Post a Comment for "Java.sql.sqlexception: Fail To Convert To Internal Representation: While Passing Arraylist To Oracle.sql.array"