Java JDBC Database Metadata getDBProduct(Connection conn)

Here you can find the source of getDBProduct(Connection conn)

Description

get DB Product

License

Open Source License

Declaration

public static String getDBProduct(Connection conn) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private static final String DATABASE_REGEX = ".*(db2|oracle|mysql|sql server|hive|asterdata|gbase|postgresql).*";

    public static String getDBProduct(Connection conn) {
        DatabaseMetaData metaData = null;
        String result = "";

        try {/*ww  w .j  a va 2s .c  om*/
            metaData = conn.getMetaData();
            String driverName = metaData.getDriverName();

            Pattern pattern = Pattern.compile(DATABASE_REGEX);
            Matcher m = pattern.matcher(driverName.toLowerCase());
            if (m.matches()) {
                result = m.group(1).replace(" ", "");
            }
            if ("".equals(result)) {
                result = "asterdata";
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return result;
    }
}

Related

  1. getDatabaseId(DatabaseMetaData md)
  2. getDatabaseInfo(Connection connection_)
  3. getDatabaseMetaData(Connection con)
  4. getDatabaseType(DatabaseMetaData metaData)
  5. getDBMSName(Connection conn)
  6. getDBTables(DatabaseMetaData metaData, String dataBase, String user)
  7. getDbType(Connection connection)
  8. getDBUsers(DatabaseMetaData metaData)
  9. getDriverSpecificSettings(Connection connection, String defaultUnionColumnValue)