List of utility methods to do JDBC Database Metadata
String | getForeignKeyDeferrability(int code) get Foreign Key Deferrability switch (code) { case DatabaseMetaData.importedKeyInitiallyDeferred: return "Initially deferred"; case DatabaseMetaData.importedKeyInitiallyImmediate: return "Initially immediate"; case DatabaseMetaData.importedKeyNotDeferrable: return "Not deferrable"; return "???"; |
int | getJDBCMajorVersion(Connection conn) Get the JDBC version, inferring it from the driver. try { conn.getClass().getMethod("setSavepoint", null); DatabaseMetaData meta = conn.getMetaData(); Method method = meta.getClass().getMethod("getJDBCMajorVersion", null); return ((Number) method.invoke(meta, null)).intValue(); } catch (Throwable t) { return 2; |
String | getNullableDescription(int type) get Nullable Description switch (type) { case DatabaseMetaData.typeNoNulls: return "No"; case DatabaseMetaData.typeNullable: return "Yes"; default: return "Unknown"; |
String | getOnly1PrimaryKey(Connection conn, String tableName) get Only Primary Key ResultSet rs = null; try { String pkName = null; DatabaseMetaData dbMeta = conn.getMetaData(); rs = dbMeta.getPrimaryKeys(null, null, tableName.toUpperCase()); if (rs.next()) { pkName = rs.getString("COLUMN_NAME"); return pkName; } finally { try { rs.close(); } catch (Exception e) { |
Set | getPrimaryKey(DatabaseMetaData metadata, String tableName) Returns a table's primary key columns as a Set of strings. Set<String> columns = new HashSet<String>(); ResultSet keys = metadata.getPrimaryKeys(metadata.getConnection().getCatalog(), metadata.getUserName(), tableName); while (keys.next()) { columns.add(keys.getString(PRIMARY_PK_COL_NAME)); keys.close(); return columns; ... |
String | getPrimaryKeyColumn(DatabaseMetaData md, String TableName) get Primary Key Column String PK_Col = null; ResultSet rs2 = md.getPrimaryKeys(null, null, TableName); while (rs2.next()) { String[] items = getResultSetStrings(rs2); if (PK_Col == null) { PK_Col = rs2.getString(4); } else { PK_Col = null; ... |
List | getPrimaryKeyColumnNames(Connection connection, String tableName) get Primary Key Column Names List<String> primaryKeyColumnNames = new LinkedList<String>(); DatabaseMetaData dbm = connection.getMetaData(); ResultSet rs = dbm.getPrimaryKeys(null, null, tableName); while (rs.next()) { String keyColumnName = rs.getString("COLUMN_NAME"); primaryKeyColumnNames.add(keyColumnName); rs.close(); ... |
List | getPrimaryKeys(Connection conn, String tableName) get Primary Keys ResultSet rs = null; try { List<String> pkNames = new ArrayList<String>(); DatabaseMetaData dbMeta = conn.getMetaData(); rs = dbMeta.getPrimaryKeys(null, null, tableName.toUpperCase()); while (rs.next()) { pkNames.add(rs.getString("COLUMN_NAME")); return pkNames; } finally { try { rs.close(); } catch (Exception e) { |
String | getQualifiedTableName(DatabaseMetaData dbmd, String catalog, String schema, String table, boolean useQuotes) Return a fully qualified table name. boolean catalogSupported = dbmd.supportsCatalogsInTableDefinitions(); boolean schemaSupported = dbmd.supportsSchemasInTableDefinitions(); String quote = dbmd.getIdentifierQuoteString(); String separator = dbmd.getCatalogSeparator(); if (separator == null || separator.trim().length() == 0) { separator = "."; StringBuilder sb = new StringBuilder(); ... |
String | getSchemaPattern(final DatabaseMetaData dbData, String schemaName) Lookup schema name according do database metadata see JIRA-28526 this method needs to be coherent with #convertToSchemaTableName(String,java.sql.DatabaseMetaData) and ModelEntity#getTableName(org.ofbiz.core.entity.config.DatasourceInfo) if (dbData.supportsSchemasInTableDefinitions()) { if (schemaName != null && schemaName.length() > 0) { return schemaName; } else if ("Oracle".equalsIgnoreCase(dbData.getDatabaseProductName())) { return dbData.getUserName(); return null; ... |