How do I use DatabaseMetaData to get table column names?

Share:

In this example we are using the DatabaseMetaData to retrieve table’s column names. The metadata information can be obtained by calling the connection.getMetaData(). Next, we can then get a ResultSet object by calling metadata.getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern).

From this result set COLUMN_NAME, TYPE_NAME, COLUMN_SIZE and others information can be read.

A bit information of stocks table described below: