Here you can find the source of getDbType(Connection connection)
Parameter | Description |
---|---|
connection | current DB Connection |
Parameter | Description |
---|---|
SQLException | an exception |
public static String getDbType(Connection connection) throws SQLException
//package com.java2s; /**//from ww w. j av a 2 s.c o m * The contents of this file are subject to the license and copyright * detailed in the LICENSE and NOTICE files at the root of the source * tree and available online at * * http://www.dspace.org/license/ */ import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.Locale; public class Main { public static final String DBMS_POSTGRES = "postgres"; public static final String DBMS_ORACLE = "oracle"; public static final String DBMS_H2 = "h2"; /** * Determine the type of Database, based on the DB connection. * * @param connection current DB Connection * @return a DB keyword/type (see DatabaseUtils.DBMS_* constants) * @throws SQLException */ public static String getDbType(Connection connection) throws SQLException { DatabaseMetaData meta = connection.getMetaData(); String prodName = meta.getDatabaseProductName(); String dbms_lc = prodName.toLowerCase(Locale.ROOT); if (dbms_lc.contains("postgresql")) { return DBMS_POSTGRES; } else if (dbms_lc.contains("oracle")) { return DBMS_ORACLE; } else if (dbms_lc.contains("h2")) // Used for unit testing only { return DBMS_H2; } else { return dbms_lc; } } }