Java ResultSetMetaData Interface

The metadata means data about data i.e. we can get further information from the data.

If you have to get metadata of a table like total number of column, column name, column type etc. , ResultSetMetaData interface is useful because it provides methods to get metadata from the ResultSet object.

Commonly Used Methods Of Resultsetmetadata Interface

MethodDescription
public int getColumnCount()throws SQLExceptionIt returns the total number of columns in the ResultSet object.
public String getColumnName(int index)throws SQLExceptionIt returns the column name of the specified column index.
public String getColumnTypeName(int index)throws SQLExceptionIt returns the column type name for the specified index.
public String getTableName(int index)throws SQLExceptionIt 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. Syntax:

Example of ResultSetMetaData interface :

Output:

Total columns: 2
Column Name of 1st column: ID
Column Type Name of 1st column: NUMBER





Latest Courses