List of utility methods to do JDBC Database Metadata
Map | getSchemas(Connection c) get Schemas DatabaseMetaData dmd = c.getMetaData(); ResultSet rs = null; try { rs = dmd.getSchemas(); Map map = new HashMap(); List l; while (rs.next()) { String schema = rs.getString(1); ... |
String | getSimplifiedURL(final DatabaseMetaData metadata) Returns a simplified form of the URL (truncated before the first ? String url = metadata.getURL(); int s1 = url.indexOf('?'); if (s1 < 0) s1 = url.length(); int s2 = url.indexOf(';'); if (s2 < 0) s2 = url.length(); return url.substring(0, Math.min(s1, s2)); ... |
List | getTableColumns(Connection connection, String selectedTable) get Table Columns ResultSet rs = null; try { DatabaseMetaData meta = connection.getMetaData(); rs = meta.getColumns(null, null, selectedTable, null); ArrayList<String> columnNames = new ArrayList<String>(); while (rs.next()) { columnNames.add(rs.getString(4)); return columnNames; } finally { closeResultSet(rs); closeConnection(connection); |
Map | getTableMetadata(Connection connection, String tableName) get Table Metadata Map<String, Map<String, String>> tableMetadatas = new HashMap<String, Map<String, String>>(); DatabaseMetaData metadata = connection.getMetaData(); ResultSet resultSet = metadata.getColumns(null, null, tableName, null); while (resultSet.next()) { Map<String, String> metaDataMap = new HashMap<String, String>(); String name = resultSet.getString("COLUMN_NAME"); String type = resultSet.getString("TYPE_NAME"); int size = resultSet.getInt("COLUMN_SIZE"); ... |
Set | getTableNames(Connection conn) get Table Names DatabaseMetaData dbmd = conn.getMetaData();
return getTableNames(conn, dbmd.getUserName());
|
List | getTableNames(DatabaseMetaData dbMD) get Table Names ResultSet rs = dbMD.getTables(null, null, null, null); List results = new ArrayList(); while (rs.next()) { results.add(rs.getString(TABLE_NAME)); safeClose(rs); return results; |
boolean | isDB2(DatabaseMetaData metadata) Comment method "isDB2". if (metadata != null && metadata.getDatabaseProductName() != null && metadata.getDatabaseProductName().indexOf(IBM_DB2_ZOS_PRODUCT_NAME) > -1) { return true; return false; |
boolean | isDerbyDatabase(DatabaseMetaData metaData) is Derby Database return Pattern.matches(".*derby.*", metaData.getDatabaseProductName().toLowerCase()); |
boolean | isExistsTable(Connection con, String schema, String tableName) is Exists Table DatabaseMetaData dmd = con.getMetaData(); ResultSet rs = dmd.getTables(null, schema, "%", null); try { tableName = tableName.toUpperCase(); while (rs.next()) { String tableNameTmp = rs.getString("TABLE_NAME"); if (tableName.equals(tableNameTmp.toUpperCase())) { return true; ... |
boolean | isIdGenerated(DatabaseMetaData metaData) is Id Generated return isDerbyDatabase(metaData) || isMySQLDatabase(metaData) || isOracleDatabase(metaData);
|