×

DatabaseMetaData in Java

The Data about another data is called Meta data. The DatabaseMetaData interface has the meta data of the database present in the system. It consists of database product name, total no of tables, version, total number of views etc.

Methods

  1. getDriverName():
    In this method, used to get the name of database driver.
  2. getDriverVersion():
    In this method, used to get the version of database driver.
  3. getUserName():
    In this method, used to get the username of database.
  4. getDatabaseProductName():
    In this method, used to get the name of the product of database.
  5. getDatabaseProductVersion():
    In this method, used to get the product version of database.

Code 1:

// program for DatabaseMetaData
import java.sql.*;
class DbMetaData
{
public static void main(string args[])
{
String url =“jdbc:mysql://localhost//DB”;
Connection con = DriverManager.getConnection(url,”root”,”password”);
DatabaseMetaData DBMD = con.getMetaData();
System.out.println(“Driver Name”+DBMD.getDriverName());
System.out.println(“Driver Version”+DBMD.getDriverVersion());
System.out.println(“User Name”+DBMD.getUserName());
System.out.println(“Database Product Name”+DBMD.getDatabaseProductName());
System.out.println(“Database Product Version”+DBMD.getDatabaseProductVersion());
con.close();
}
}

By the Above program we can get the details of the Database Details like, Version , username, Product Name, Product Version.

Code 2:

import java.sql.*;
class DbMetaData2
{
public static void main(String args[])
{
Connection con = DriverManager.getConnection(url,”root”,”password”);
DatabaseMetaData DBMD = con.getMetaData();
String table[] = {“Table”};
ResultSet rs = DBMD.getTables(null,null,null,table);
while(rs.next())
{
System.out.println(rs.getString(3));
}
con.close();
}
} 

This program is used to display Number of tables present in the database.

Code 3:

import java.sql.*;
class DbMetaData2
{
public static void main(String args[])
{
Connection con = DriverManager.getConnection(url,”root”,”password”);
DatabaseMetaData DBMD = con.getMetaData();
String table[] = {“View”};
ResultSet rs = DBMD.getTables(null,null,null,table);
while(rs.next())
{
System.out.println(rs.getString(3));
}
con.close();
}
} 

This program is used to display the Views present in the database.


Related Topics

Java Create File

A File is a hypothetical way, which has no genuine presence. It is very much like while "using" that File that the major real activity of putting away something in...

5 minutes read.

Java String toUpperCase() methods

Java String toUpperCase() method is used to convert all the characters of the String into upper case. Syntax public String toUpperCase() public String toUpperCase(Locale locale) Returns It returns upper case String. Java String toUpperCase() Example 1: public...

1 minute read.

Java Tutorial

What is Java? Java is an object-oriented, robust, secured and platform-independent programming language. With the help of Java Programming, we can develop console, window, web, enterprise and mobile applications. Java language was...

22 minutes read.

Empty Statement in Java

The three sorts of statements in Java are control, expression, and declaration statements. Additionally, another statement is referred to as an empty statement. In this section, we will discuss about...

4 minutes read.

Java Math ulp() Method

The ulp() method of Java Math class returns the size of an ulp of the argument. Syntax: public static double ulp(double x)public static float ulp(float x) Parameters: The parameter ‘x’ represents the floating-point number...

2 minutes read.

Hidden classes in Java

There specifically are some APIs available in the market that generally is harmful to be used in our programs specifically literally, and until JDK 15, there, for all intents and...

4 minutes read.

Program to Find Square Root of a Number Without sqrt Method in Java

The Java Math class sqrt () function can be used to determine the square root of a number. In this section, we'll write a Java program to find a number's...

3 minutes read.

Java Break Keyword

Break: The word Break is a keyword or a statement in a java programming language.This Keyword break is used to stop the execution of the loop or switch statements etc.The loop...

3 minutes read.

Vectors in Java

Vector Class We may make resizable arrays comparable to the ArrayList class using the Vector class, which implements the List interface. A vector is similar to a dynamic collection that can...

4 minutes read.

Java Integer signum() method

The signum() method of Java Integer class returns the signum function of the specified int value. Syntax public static int signum (int i)  Parameters The parameter ‘i’ represents the value whose signum is to...

1 minute read.

Untouchable Number in Java

If a number N cannot be divided properly by any positive number, it is said to be an untouchable number. Additionally known as nonaliquot numbers. The sequence is A005114 from...

3 minutes read.

Java Try-Catch Block

Java Try Block The handling of the exceptions in a block of code is done with the help of java try block. It throws the code that is enclosed in a...

3 minutes read.

Hashing Algorithm in Java

The hashing algorithm is a method that maps data to the fixed-length hash. The Java hash-based algorithm employs a cryptographic mathematical operation. A hash technique or hash function is supposed...

8 minutes read.

Perfect Number in Java

The concept of a perfect number in Java will be defined in this chapter, along with creating Program code that determine whether a specific number is perfect or not. Additionally,...

4 minutes read.

What is Core Java?

The fundamental Java, which includes the fundamental idea of the Java programming language, is referred to as "Core Java." The definition of "Core" is the core idea of something. Core...

3 minutes read.

Sleep Time in Java

Sleep is amethod in java that is related to thread class and it is a concept of multithreading and is used to stop the execution of the current thread a...

4 minutes read.

Java Boolean toValue() Method

The valueOf() method of Java Boolean class returns a Boolean object representing the given Boolean or String value. It returns true, if the specified Boolean or string object is true...

2 minutes read.

Java IO file not found exception

One of the exception classes offered by the java.io package is FileNotFoundException. An exception is raised when we attempt to access a file that isn't present in the system. It...

4 minutes read.

Java Control Statements

Control Statements: Control statements in Java can also be referred to as decision-making while dealing with different problems. Control statements are helpful to sort out the flow of the program or...

7 minutes read.

Calculator Program in Java

Calculator Program in Java A calculator performs the basic mathematical operations such as addition, subtraction, multiplication, etc. In this section, we will create a calculator program in Java using switch case...

5 minutes read.