Java JDBC Database Metadata getDatabaseType(DatabaseMetaData metaData)

Here you can find the source of getDatabaseType(DatabaseMetaData metaData)

Description

get Database Type

License

Apache License

Declaration

public static String getDatabaseType(DatabaseMetaData metaData) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import com.google.common.base.Strings;

import java.sql.*;

public class Main {
    public final static String DB_TYPE_ORACLE = "ORACLE";
    public final static String DB_TYPE_MYSQL = "MYSQL";
    public final static String DB_TYPE_OTHEER = "OTHER";

    public static String getDatabaseType(Connection con) throws SQLException {
        return getDatabaseType(getDatabaseMetaData(con));
    }/* www.  j  a  va  2 s  .c  om*/

    public static String getDatabaseType(DatabaseMetaData metaData) throws SQLException {
        if (metaData != null) {
            String name = metaData.getDatabaseProductName();
            if (!Strings.isNullOrEmpty(name) && name.trim().toUpperCase().contains(DB_TYPE_MYSQL)) {
                return DB_TYPE_MYSQL;
            } else if (!Strings.isNullOrEmpty(name) && name.trim().toUpperCase().contains(DB_TYPE_ORACLE)) {
                return DB_TYPE_ORACLE;
            }
        }
        return DB_TYPE_OTHEER;
    }

    public static DatabaseMetaData getDatabaseMetaData(Connection con) throws SQLException {
        return con.getMetaData();
    }
}

Related

  1. getColumns(Connection connection, String name)
  2. getColumnSize(Connection con, String tableName, String columnName)
  3. getDatabaseId(DatabaseMetaData md)
  4. getDatabaseInfo(Connection connection_)
  5. getDatabaseMetaData(Connection con)
  6. getDBMSName(Connection conn)
  7. getDBProduct(Connection conn)
  8. getDBTables(DatabaseMetaData metaData, String dataBase, String user)
  9. getDbType(Connection connection)