JDBC – ResultSet and ResultSetMetaData

ResultSet interface in detail:

  • ResultSet object returned by executeQuery() method or execute() method.
  • ResultSet Object holds the records information collect through select query.
  • The object of ResultSet maintains a cursor pointing to a row of a table.
  • Initially, cursor points to before the first row.
Method NameDescription
public boolean next():It is used to move the cursor to the one row next from the current position.
public int getInt(int columnIndex):It is used to return the data of specified column index of the current row as int.
public int getInt(String columnName):It is used to return the data of specified column name of the current row as int.
public String getString(int columnIndex):It is used to return the data of specified column index of the current row as String.
public String getString(String columnName):It is used to return the data of specified column name of the current row as String.

Java ResultSetMetaData Interface:

  • The metadata means data about data.
  • If you have to get metadata of a table like total number of column, column name, column type etc.
  • Methods of ResultSetMetaData interface as follows:
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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top