java.sql.ARRAY到ArrayList <string []> OracleCallableStatement </string []>

时间:2014-04-24 19:11:31

标签: java sql arrays oracle object

我从ARRAY收到oralce sql in java并将其写入java.sql.ARRAY。此数组的类型为VARRAY OBJECT。如何将此类型转换为ArrayList?

1 个答案:

答案 0 :(得分:4)

假设您实际上获得了String[]的数组,您应该可以使用类似的内容 -

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;
}