List All Column Names of Table using Java

We can list all column names of table using java.sql.DatabaseMetaData.getColumns() method. The getColumn method accepts String catalog, String schemaPattern, String tableNamePattern and String columnNamePattern parametres. It retrieves a description of table columns available in the specified catalog. The method return ResultSet where each row is a column description.

Example to list all column names of table using java:-

output:-

Description of parameters available in getColumns() method:-

catalog:- is the name of catalog. it must match with the catalog name stored in the database, the catalog can be null, means should not be used to narrow the search or “” means retrieves those without a catalog.

schemaPattern:- is a schema name pattern. it must match with the schema name stored in the database, schemaPattern can be “” means retrieves those without a schema or null that means schema name should not be used to narrow the search.

tableNamePattern:- is a table name pattern. it must match with the table name stored in the database.

columnNamePattern:- is a column name pattern. it must match with the column name stored in the database.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.