• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Java » Jdbc » METADATA in JDBC
Next →
← Prev

METADATA in JDBC

By Dinesh Thakur

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

We’ll be covering the following topics in this tutorial:

  • Database Metadata
  • ResultSetMetaData

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.

 

Example:

DatabaseMetaDatadbmd=con.getMetaData();

 

Use

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

 

//DBMetaData.java

import java.io.*;

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”);

                 }

}

ResultSetMetaData

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:

 

//ResuleSetMetaDataTest

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.in);

                     System.out.println(“Enter table name”);

                     String tname=sc.next();

                     //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” ) ;

                        }

                            System.out.println(“\n”);

                            //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(“\n”);

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

                                    while(rs.next())

                                      {

                                           System.out.println(rs.getString(1)+”\t\t”+rs.getString(2)+”\t\t”+rs.getString(3));

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

                                                    {

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

                                                     }*/

                                      }

                                  rs.close() ;

                                  st.close() ;

                                  cn.close();

                }

}

You’ll also like:

  1. What is Metadata OR Data Dictionary?
  2. Accessing Metadata in Java Servlet
  3. What is JDBC API? Important Goals of JDBC-API.
  4. JDBC Connection Pooling
  5. JDBC Join
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

SQL Tutorials

SQL Tutorials

  • SQL - Home
  • SQL - Select
  • SQL - Create
  • SQL - View
  • SQL - Sub Queries
  • SQL - Update
  • SQL - Delete
  • SQL - Order By
  • SQL - Select Distinct
  • SQL - Group By
  • SQL - Where Clause
  • SQL - Select Into
  • SQL - Insert Into
  • SQL - Sequence
  • SQL - Constraints
  • SQL - Alter
  • SQL - Date
  • SQL - Foreign Key
  • SQL - Like Operator
  • SQL - CHECK Constraint
  • SQL - Exists Operator
  • SQL - Drop Table
  • SQL - Alias Syntax
  • SQL - Primary Key
  • SQL - Not Null
  • SQL - Union Operator
  • SQL - Unique Constraint
  • SQL - Between Operator
  • SQL - Having Clause
  • SQL - Isnull() Function
  • SQL - IN Operator
  • SQL - Default Constraint
  • SQL - Minus Operator
  • SQL - Intersect Operator
  • SQL - Triggers
  • SQL - Cursors

Advanced SQL

  • SQL - Joins
  • SQL - Index
  • SQL - Self Join
  • SQL - Outer Join
  • SQL - Join Types
  • SQL - Cross Join
  • SQL - Left Outer Join
  • SQL - Right Join
  • SQL - Drop Index
  • SQL - Inner Join
  • SQL - Datediff() Function
  • SQL - NVL Function
  • SQL - Decode Function
  • SQL - Datepart() Function
  • SQL - Count Function
  • SQL - Getdate() Function
  • SQL - Cast() Function
  • SQL - Round() Function

Other Links

  • SQL - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW