java tutorial - Java resultsetmetadata | Resultsetmetadata - java programming - learn java - java basics - java for beginners
Java ResultSetMetaData Interface
- java.sql.ResultSetMetaData is also one of the frequently used interface in the JDBC API.
- This interface provides quick overview about a ResultSet object like number of columns, column name, data type of a column etc.
- You often need this info about a ResultSet object before processing the actual data of a ResultSet.
ResultSetMetaData In JDBC
- ResultSetMetaData is an interface in java.sql package of JDBC API which is used to get the metadata about a ResultSet object.
- Whenever you query the database using SELECT statement, the result will be stored in a ResultSet object.
- Every ResultSet object is associated with one ResultSetMetaData object.
- This object will have all the meta data about a ResultSet object like schema name, table name, number of columns, column name, datatype of a column etc.
- You can get this ResultSetMetaData object using getMetaData() method of ResultSet.
Methods of ResultSetMetaData interface
Method | Description |
---|---|
public int getColumnCount()throws SQLException | Returns the total number of columns in ResultSet object. |
public String getColumnName(int index)throws SQLException | Returns the column name of specified column index. |
public String getColumnTypeName(int index)throws SQLException | Returns the column type name for the specified index. |
public String getTableName(int index)throws SQLException | Returns the table name for the specified column index. |
How to get the object of ResultSetMetaData ?
- The getMetaData() method of ResultSet interface returns the object of ResultSetMetaData.