Java DatabaseMetaData list database features

Description

Java DatabaseMetaData list database features

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

public class Main {
  public static void main(String[] args) {
    Connection conn = null;/*w  ww .j a  v  a 2s  .c o m*/
    try {
      conn = openConnection();

      // Get DatabaseMetaData object
      DatabaseMetaData dbmd = conn.getMetaData();

      System.out.println("About the database...");

      String dbName = dbmd.getDatabaseProductName();
      String dbVersion = dbmd.getDatabaseProductVersion();
      String dbURL = dbmd.getURL();
      System.out.println("Database Name: " + dbName);
      System.out.println("Database Version: " + dbVersion);
      System.out.println("Database URL: " + dbURL);

      System.out.printf("%nAbout the JDBC driver...%n");
      String driverName = dbmd.getDriverName();
      String driverVersion = dbmd.getDriverVersion();
      System.out.println("Driver Name: " + driverName);
      System.out.println("Driver Version: " + driverVersion);

      System.out.printf("%nAbout the JDBC driver supported features...%n");
      boolean ansi92BiEntry = dbmd.supportsANSI92EntryLevelSQL();
      boolean ansi92Intermediate = dbmd.supportsANSI92IntermediateSQL();
      boolean ansi92Full = dbmd.supportsANSI92FullSQL();
      boolean supportsBatchUpdates = dbmd.supportsBatchUpdates();
      System.out.println("Supports Entry Level ANSI92 SQL: " + ansi92BiEntry);
      System.out.println("Supports Intermediate Level ANSI92 SQL: " + ansi92Intermediate);
      System.out.println("Supports Full Level ANSI92 SQL: " + ansi92Full);
      System.out.println("Supports batch updates: " + supportsBatchUpdates);
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      // close connection
    }
  }

  static Connection openConnection() {
    // open your database connection
    return null;
  }
}



PreviousNext

Related