Użyj java.sql.ResultSetMetaData.getColumnTypeName()
:
Konfiguracja Oracle :
CREATE OR REPLACE TYPE random_array IS TABLE OF VARCHAR2(42);
/
Jawa :
Class.forName("oracle.jdbc.OracleDriver");
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl",
"username",
"password"
);
PreparedStatement st = con.prepareStatement(
"SELECT random_array( 'a', 'b', 'c' ) AS array FROM DUAL"
);
ResultSet rs = st.executeQuery();
while( rs.next() )
{
String type = rs.getMetaData().getColumnTypeName(1);
String[] data = (String[]) rs.getArray(1).getArray();
System.out.println( type + ": " + Arrays.toString( data ) );
}
st.close();
con.close();
Wyjście :
SCHEMA_NAME.RANDOM_ARRAY: [a, b, c]
Jeśli chcesz wrócić do Oracle i znaleźć typ elementów kolekcji, których możesz użyć:
SELECT ELEM_TYPE_NAME,
LENGTH,
PRECISION,
SCALE
FROM ALL_COLL_TYPES
WHERE TYPE_NAME = 'RANDOM_ARRAY'
AND OWNER = 'SCHEMA_NAME';
Które wyjścia:
ELEM_TYPE_NAME LENGTH PRECISION SCALE
-------------- ------ --------- -----
VARCHAR2 42