java.sql.ResultSetMetaData.getColumnTypeName()
:
オラクルのセットアップ :
CREATE OR REPLACE TYPE random_array IS TABLE OF VARCHAR2(42); /
プレ>Java :
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();
プレ>出力 :
SCHEMA_NAME.RANDOM_ARRAY: [a, b, c]
プレ>その後、Oracle に戻って、使用できるコレクション要素のタイプを見つけたい場合:
SELECT ELEM_TYPE_NAME, LENGTH, PRECISION, SCALE FROM ALL_COLL_TYPES WHERE TYPE_NAME = 'RANDOM_ARRAY' AND OWNER = 'SCHEMA_NAME';
プレ>どの出力:
ELEM_TYPE_NAME LENGTH PRECISION SCALE -------------- ------ --------- ----- VARCHAR2 42
プレ>