by Dinesh Thakur Category: JDBC

Data about data is called metadata. That means data about column names, data type names of database software etc. JDBC supported Metadata programming areas follows:

1 Database Metadata

2 ResultSet Metadata

Database Metadata

By this programmer can get limitations and capabilities of underlying Database software like database software name, versions, max chars in table, etc. Database- Metadata object means it the object of a java class that implements java.sql. Database Metadata (interface). Programmer call various methods on Database Metadata object to gather much information about underlying database software.






DatabaseMetaData programming is useful while developing GUI tools for Database software like sqlyog, mysql front, etc.

JDBC Metadata Programming is in no way related to performing CURD operations on database. It is given to gather additional details about database software and its tables. If certain JDBC driver cannot retrieve certain information about database then it returns zero "0" or "null" value while working with DatabaseMetaData object.


Example application




import java.sql.*;

public class DBMetaData


                  public static void main (String args[ ]) throws SQLException,ClassNotFoundException


                       Class.forName("Sun.jdbc.odbc.JdbcOdbcDrivet") ;

                       Connection con=DriverManager.getConnection("jdbc:odbc:oradsn","scott","tiger");

                       DatabaseMetaData dbmd=con.getMetaData();

                       System.out.println("database version:"+dbmd.getDatabaseProductVersion()+"\n");

                       System.out.println("database name:"+dbmd.getDatabaseProductName()+"\n");

                       System.out.println("sql keywords:" +dbmd.getSQLKeywords() +"\n");

                       System.out.println("numeric functions: "+dbmd.getNumericFunctions () +"\n") ;

                       System.out.println("String functions: "+dbmd.getStringFunctions ()+"\n" );

                       System.out.println ("System functions:" +dbmd.getSystemFunctions()+"\n") ;

                       System.out.println("Searc string Escape:" +dbmd.getSearchStringEscape ()+"\n");

                       System.out.println ("getMaxRowSize: "+dbmd.getMaxRowSize()+"\n");

                       System.out.println ("getMaxstatementLength:"+dbmd.getMaxStatementLength() +"\n");

                       System.out.println("get maximum tables in a select query:"+dbmd.getMaxTablesInSelect()+"\n");

                       System.out.println("get maximum length of table name:"+dbmd.getMaxTableNameLength()+"\n");

                       System.out.println("jdbcapi version is :"+dbmd.getJDBCMajorVersion()+"\n");




It is used to gather more information about database table that is represented by JBDC ResultSet object. It is used to get no of columns, column name, column data types, etc., information from database table.

ResultSetMetaData object means it is the object of JBDC driver supplied Java class that implements java.sql.ResultSet.MetaData(interface). This object is very useful while generating reports based on database table data; like progress report, sales report, etc.


Method calling

ResultSet rs =st.executeQuery("select * from emp");

ResultSetMetaData rsmd=rs.getMetaData();


Here we have taken college table as follows:



import java.sql.*;

import java.util.*;

public class ResultSetMetaDataTest


               public static void main(String args[]) throws SQLException,ClassNotFoundException


                     //read inputs

                     Scanner sc = new Scanner(;

                     System.out.println("Enter table name");


                     //create jdbc connection

                     Class.forName("oracle.jdbc.driver.OracleDriver") ;

                     Connection cn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracl","scott","tiger");

                     Statement st=cn.createStatement();

                     ResultSet rs=st.executeQuery ("select * from "+tname);

                     ResultSetMetaData rsmd=rs.getMetaData();

                     int colcnt=rsmd.getColumnCount();

                     //System.out.println("Columns present in the table are:\n") ;

                     for(int i=1;i<=colcnt;i++)


                            System.out.print (rsmd.getColumnLabel(i)+"\t\t" ) ;



                            //Systeml.out.println("datatypes of the columns are:\n");

                            for(int i=1;i<=colcnt;++i)


                                    System.out.print (rsmd.getColumnTypeName(i)+"\t");



                                    //System.out.println("records of the table are:\n");




                                            /*for (int i=1;  i<=colcnt; ++i)


                                                        System.out.println(rs. getString(i) +"\ t ") ;



                                  rs.close() ;

                                  st.close() ;




About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.