How do I get database product information?

The code below helps you to get some product information about the database that you use in creating your program. You can retrieve database information such at the major and minor version of the product, the database product name and its release version.

package org.kodejava.example.sql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

public class DriverInfo {
    private static final String DRIVER = "com.mysql.jdbc.Driver";
    private static final String URL = "jdbc:mysql://localhost/kodejava";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "";

    public static void main(String[] args) throws Exception {
        Connection connection = null;
        try {
            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);

            DatabaseMetaData metadata = connection.getMetaData();

            int majorVersion = metadata.getDatabaseMajorVersion();
            System.out.println("majorVersion = " + majorVersion);
            int minorVersion = metadata.getDatabaseMinorVersion();
            System.out.println("minorVersion = " + minorVersion);

            String productName = metadata.getDatabaseProductName();
            System.out.println("productName = " + productName);

            String productVersion = metadata.getDatabaseProductVersion();
            System.out.println("productVersion = " + productVersion);
        } catch (SQLException e) {
        } finally {
            if (connection != null) {

And here are the result:

majorVersion = 5
minorVersion = 0
productName = MySQL
productVersion = 5.0.51a

Wayan Saryada

Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. You can support my works by donating here. Thank you šŸ™‚.

Leave a Reply

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