List of utility methods to do JDBC Database Metadata
boolean | isMysql(DatabaseMetaData metadata) is Mysql boolean result = false; try { if (metadata != null && metadata.getDriverName() != null && metadata.getDatabaseProductName() != null && metadata.getDatabaseProductName().toUpperCase().indexOf("MYSQL") > -1) { result = true; } catch (SQLException e) { result = false; ... |
boolean | isOracleForSid(DatabaseMetaData metadata, String oracleProduct) is Oracle For Sid if (metadata != null && metadata.getDatabaseProductName() != null && metadata.getDatabaseProductName().indexOf(oracleProduct) > -1) { return true; return false; |
boolean | isSybase(DatabaseMetaData metadata) is Sybase boolean result = false; if (metadata != null && "org.talend.commons.utils.database.SybaseDatabaseMetaData" .equals(metadata.getClass().getName())) { result = true; return result; |
boolean | isSybaseDb(DatabaseMetaData metaData) Detects whether or not the given metadata describes the connection to a Sybase database or not. String dbProductName = metaData.getDatabaseProductName(); boolean isSybase = (dbProductName != null && dbProductName.equals(DB_PRODUCT_SYBASE)); return isSybase; |
void | printExistingTables(Connection conn) print Existing Tables DatabaseMetaData dbmd = conn.getMetaData(); System.out.println("********************************************"); ResultSet rs = dbmd.getTables(null, null, null, null); while (rs.next()) { System.out.println(rs.getString("TABLE_NAME")); System.out.println("********************************************"); |
void | printMetaData(Connection con) print Meta Data try { DatabaseMetaData meta = con.getMetaData(); System.out.println("Driver: " + meta.getDriverName() + " " + meta.getDriverMajorVersion() + "." + meta.getDriverMinorVersion()); System.out.println("DB: " + meta.getDatabaseProductName() + " " + meta.getDatabaseMajorVersion() + "." + meta.getDatabaseMinorVersion() + " (" + meta.getDatabaseProductVersion() + ")"); } catch (SQLException e) { System.out.println("Error: " + e.getMessage()); ... |
void | printTableExistence(String name, Connection conn) print Table Existence if (tableExists(name, conn)) System.out.println(name + " exists"); else System.out.println(name + " does not exist"); |
boolean | sequenceExists(String seqName, Connection conn) sequence Exists DatabaseMetaData dbmd = conn.getMetaData(); if (dbmd.getURL().startsWith("jdbc:postgresql:")) { return returnsAnyRows( "SELECT * from pg_class where relname = '" + seqName.toLowerCase() + "' AND relkind = 'S'", conn); } else if (dbmd.getURL().startsWith("jdbc:hsqldb:")) { String whereClause = "WHERE sequence_name = '" + seqName.toUpperCase() + "'"; try { ... |
boolean | tableExists(Connection con, String table) table Exists DatabaseMetaData meta = con.getMetaData(); ResultSet rs = meta.getTables("", null, table, null); return rs.next(); |
boolean | tableExists(Connection connection, String tableName) table Exists for (String s : getTableNames(connection)) { if (s.equals(tableName)) { return true; return false; |