How to get the name of column in a table with JDBC?

How to get the name of column in a table with JDBC?


Column name JDBC

ResultSetMetaData interface comes with methods to know the metadata of a table. Metadata is knowing the number of columns, name of each column etc. Example (of column name JDBC) prints the first column name and all the column names of table Employee.

Example on column name JDBC

  1. getMetaData() is a method of ResultSet interface. The method returns an object of ResultSetMetaData interface.
  2. ResultSetMetaData object contains the metadata of the table.
  3. getColumnCount() method of ResultSetMetaData interface returns the number of columns(fields) of a table.
  4. getColumnName(int columnNumber) method of ResultSetMetaData interface returns the name of the column, passed as parameter.

System.out.println(rsmd.getColumnName(i+1));

Columns numbers start from 1 (and not 0) but loop starts from 0.

Pass your comments and suggestions on this tutorial "column name JDBC" to improve the quality.

Leave a Reply

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