ResultSetMetaData

ResultSetMetaData (결과 집합 메타데이터)

ResultSet 객체의 열 타입과 속성에 대한 정보를 얻는 데 사용할 수 있는 객체입니다.

출처: Java API Reference

본문

다음 코드 조각은 ResultSet 객체 rs를 만들고, ResultSetMetaData 객체 rsmd를 만들어 rs가 몇 개의 열을 가지는지, rs의 첫 열이 WHERE 절에 사용될 수 있는지 알아냅니다.

ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
boolean b = rsmd.isSearchable(1);

null 허용 여부 상수로 columnNoNulls, columnNullable, columnNullableUnknown을 제공합니다.

대표적인 메서드

int getColumnCount() throws SQLException
boolean isAutoIncrement(int column) throws SQLException
boolean isNullable(int column) throws SQLException
boolean isSearchable(int column) throws SQLException
int getColumnDisplaySize(int column) throws SQLException
String getColumnLabel(int column) throws SQLException
String getColumnName(int column) throws SQLException
int getColumnType(int column) throws SQLException
String getColumnTypeName(int column) throws SQLException
int getPrecision(int column) throws SQLException
int getScale(int column) throws SQLException
String getTableName(int column) throws SQLException
String getColumnClassName(int column) throws SQLException

더 알아보기 (Learn more)

Java 공식 API