How to get number of columns in a table with JDBC?

How to get number of columns in a table with JDBC?

Number of columns in table JDBC

ResultSetMetaData interface includes many methods to find the metadata of a table like number of columns, name of each column etc. Following example prints the number of columns of table Employee.

Example on number of columns in table JDBC

Database connection is obtained using the standard three statements like Connection and Statement. You can use as well think driver also.

  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.

Pass your comments and suggestions on this tutorial number of columns in table JDBC to improve quality of content.

Leave a Reply

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