Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by njzk2, PM 77-1, Bhesh Gurung, Kevin Panko, davidethell Apr 24 '14 at 20:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

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;
}
share|improve this answer
    
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; –  user2993505 Apr 27 '14 at 10:52
    
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. –  Elliott Frisch Apr 27 '14 at 18:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.