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?
1 Answer
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;
}
2 Comments
user2993505
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;Elliott Frisch
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.