Java Utililty Methods JDBC Database Metadata

List of utility methods to do JDBC Database Metadata

Description

The list of methods to do JDBC Database Metadata are organized into topic(s).

Method

booleanisMysql(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;
...
booleanisOracleForSid(DatabaseMetaData metadata, String oracleProduct)
is Oracle For Sid
if (metadata != null && metadata.getDatabaseProductName() != null
        && metadata.getDatabaseProductName().indexOf(oracleProduct) > -1) {
    return true;
return false;
booleanisSybase(DatabaseMetaData metadata)
is Sybase
boolean result = false;
if (metadata != null && "org.talend.commons.utils.database.SybaseDatabaseMetaData" 
        .equals(metadata.getClass().getName())) {
    result = true;
return result;
booleanisSybaseDb(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;
voidprintExistingTables(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("********************************************");
voidprintMetaData(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());
...
voidprintTableExistence(String name, Connection conn)
print Table Existence
if (tableExists(name, conn))
    System.out.println(name + " exists");
else
    System.out.println(name + " does not exist");
booleansequenceExists(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 {
...
booleantableExists(Connection con, String table)
table Exists
DatabaseMetaData meta = con.getMetaData();
ResultSet rs = meta.getTables("", null, table, null);
return rs.next();
booleantableExists(Connection connection, String tableName)
table Exists
for (String s : getTableNames(connection)) {
    if (s.equals(tableName)) {
        return true;
return false;