How to Get DatabaseMetaData in Java


In this example we will show the first argument with the sign of the second argument with Math.copySign().

Source Code

package com.beginner.examples;

import com.mysql.jdbc.Driver;
import java.sql.*;
  
    public class DBInfoExample {
        public static void main(String[] args) throws SQLException, ClassNotFoundException {

        Class.forName("com.mysql.jdbc.Driver");
        
        //database connection
        Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mysql", "root", "");
        //connection informations
        DatabaseMetaData dbinfo = conn.getMetaData();
        System.out.println(dbinfo.getDriverVersion());
        System.out.println(dbinfo.getDriverName());
        System.out.println(dbinfo.getDatabaseProductName());
        System.out.println(dbinfo.getDatabaseProductVersion());
    }
}

Output:

mysql-connector-java-5.0.8 ( Revision: ${svn.Revision} )
MySQL-AB JDBC Driver
MySQL
5.6.23
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments