Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.sql.ARRAY to ArrayList<String[]> OracleCallableStatement [duplicate]

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?

like image 785
user2993505 Avatar asked Sep 21 '26 16:09

user2993505


1 Answers

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;
}
like image 138
Elliott Frisch Avatar answered Sep 23 '26 04:09

Elliott Frisch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!