3

I'm getting an ARRAY from oralce sql in java and write it to java.sql.ARRAY. This array is type of VARRAY of OBJECT. How can I convert this type to ArrayList?

0

1 Answer 1

5

Assuming you actually are getting an array of String[], you should be able to use something like -

public static List<String[]> getList(ResultSet rs) throws IOException, SQLException {
    List<String[]> al = new ArrayList<String[]>();
    java.sql.Array z = rs.getArray("my_array_column");
    for (Object obj : (Object[])z.getArray()) {
        try {
            String [] arr = (String[]) obj;
            al.add(arr);
        } catch (ClassCastException e) {
            System.out.println("Object is not a String[]");
            e.printStackTrace();
        }
    }
    return al;
}
Sign up to request clarification or add additional context in comments.

2 Comments

if I use ResultSet it would work, but I'm using JDBC and OracleCallableStatement and when i convert ARRAY to Object it' OK, but when i try to convert it to String I'm getting an error java.lang.ClassCastException: oracle.sql.STRUCT cannot be cast to [Ljava.lang.String;
Please be specific in your question. Now, what do you mean by "convert", that exception is from an invalid "cast"; that is not a conversion.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.