You are on page 1of 10

Gamified Virtual Classroom implementing

-JDBC aCTIVITY

Team 4
Satish Reddy
Naveendhar
Shantam
Savitra
Sahana
Shynitha
DatabaseMetaData Interface &
Methods
• DatabaseMetaData : These Interface gives as all the
information about database.
This MetaData is used to find Capabilities of Data
Base Management System(DBMS) with respect to JDBC
driver used to connect with the Database.
• What is Database MetaData Interface
If you want to know the background details of your
current working database, your program is connected to
which database or you project is running on which database.
• The data of database that we collect using
DatabaseMetaData interface
we can fetch all the information about the database
(Version,Username, Drivername,URL, Number of tables,,
etc) except password because the password is sensitive
information .so, this interface hides passwords to avoid
Cyber-Attacks.
Example
• Name of database
• Vendor of database
• Version of database
• what are last varsion
• Number of tables
Methods of DatabaseMetaData
interface
Commonly used methods of DatabaseMetaData
interface
• getDriverName()
• getDriverVersion()
• getUserName()
• getURL()
• getNumericFunctions()
• getStringFunctions()
• getSystemFunctions()
• getTimeDateFunctions()
Object And Syntax
How to get the object of DatabaseMetaData:

The getMetaData() method of Connection interface returns


the object of DatabaseMetaData
Syntex:public DatabaseMetaData getMetaData()throws
SQLException
Program
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
public class DatabaseMetadata {
public static void main(String args[])throws Exception {
//Getting the connection
String mysqlUrl = "jdbc:mysql://localhost:5432/satish";
Connection con = DriverManager.getConnection(mysqlUrl, "satish", "satishroot");
System.out.println("Connection established......");

//Creating the DatabaseMetaData object


DatabaseMetaData dbMetadata = con.getMetaData();
//invoke the supportsBatchUpdates() method.
boolean bool = dbMetadata.supportsBatchUpdates();
if(bool) {
System.out.println("Underlying database supports batch updates");
} else {
System.out.println("Underlying database doesnt supports batch updates");
}

//Retrieving the driver name


System.out.println(dbMetadata.getDriverName());
//Retrieving the driver version
System.out.println(dbMetadata.getDriverVersion());
//Retrieving the user name
System.out.println(dbMetadata.getUserName());
//Retrieving the URL
System.out.println(dbMetadata.getURL());
System.out.println(dbMetadata.getURL());
//Retrieving the list of numeric functions
System.out.println("Numeric functions: "+dbMetadata.getNumericFunctions());
System.out.println("");
//Retrieving the list of String functions
System.out.println("String functions: "+dbMetadata.getStringFunctions());
System.out.println("");
//Retrieving the list of system functions
System.out.println("System functions: "+dbMetadata.getSystemFunctions());
System.out.println("");
//Retrieving the list of time and date functions
System.out.println("Time and Date funtions: "+dbMetadata.getTimeDateFunctions());
}
}

You might also like