List of utility methods to do JDBC Database Metadata
String | getDatabaseId(DatabaseMetaData md) get Database Id return md.getDatabaseProductName() + " " + md.getDatabaseProductVersion(); |
Map | getDatabaseInfo(Connection connection_) get Database Info if (connection_ == null) return null; DatabaseMetaData dbMeta = connection_.getMetaData(); if (dbMeta == null) return null; Map<String, Object> info = new HashMap<String, Object>(); info.put(DATABASE_MAJOR_VERSION_KEY, new Integer(dbMeta.getDatabaseMajorVersion())); info.put(DATABASE_MINOR_VERSION_KEY, new Integer(dbMeta.getDatabaseMinorVersion())); ... |
DatabaseMetaData | getDatabaseMetaData(Connection con) get Database Meta Data return con.getMetaData();
|
String | getDatabaseType(DatabaseMetaData metaData) get Database Type 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; |
String | getDBMSName(Connection conn) get DBMS Name DatabaseMetaData dmd = conn.getMetaData();
return dmd.getDatabaseProductName();
|
String | getDBProduct(Connection conn) get DB Product DatabaseMetaData metaData = null; String result = ""; try { metaData = conn.getMetaData(); String driverName = metaData.getDriverName(); Pattern pattern = Pattern.compile(DATABASE_REGEX); Matcher m = pattern.matcher(driverName.toLowerCase()); if (m.matches()) { ... |
String[] | getDBTables(DatabaseMetaData metaData, String dataBase, String user) get DB Tables ResultSet rs = metaData.getTables(dataBase, null, user, new String[] { "TABLE" }); List<String> tables = new ArrayList<String>(); try { while (rs.next()) { tables.add(rs.getString("TABLE_NAME")); } finally { rs.close(); ... |
String | getDbType(Connection connection) Determine the type of Database, based on the DB connection. 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")) ... |
String[] | getDBUsers(DatabaseMetaData metaData) get DB Users ResultSet rs = metaData.getSchemas(); List<String> users = new ArrayList<String>(); try { while (rs.next()) { users.add(rs.getString("TABLE_SCHEM")); } finally { rs.close(); ... |
void | getDriverSpecificSettings(Connection connection, String defaultUnionColumnValue) get Driver Specific Settings if (connection != null) { DatabaseMetaData metadata = connection.getMetaData(); String dbproduct = metadata.getDatabaseProductName(); int dbmajorversion = metadata.getDriverMajorVersion(); int dbminorversion = metadata.getDriverMinorVersion(); defaultUnionColumnValue = "null"; if (dbproduct.startsWith("Microsoft SQL Server")) { defaultUnionColumnValue = "null"; ... |