Java JDBC Database Metadata isExistsTable(Connection con, String schema, String tableName)

Here you can find the source of isExistsTable(Connection con, String schema, String tableName)

Description

is Exists Table

License

Open Source License

Declaration

public static boolean isExistsTable(Connection con, String schema, String tableName) throws SQLException 

Method Source Code


//package com.java2s;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {

    public static boolean isExistsTable(Connection con, String schema, String tableName) throws SQLException {
        DatabaseMetaData dmd = con.getMetaData();
        ResultSet rs = dmd.getTables(null, schema, "%", null);
        try {/*ww  w  . ja v a  2s.  com*/
            tableName = tableName.toUpperCase();
            while (rs.next()) {
                String tableNameTmp = rs.getString("TABLE_NAME");
                if (tableName.equals(tableNameTmp.toUpperCase())) {
                    return true;
                }
            }
            return false;
        } finally {
            rs.close();
        }
    }
}

Related

  1. getTableMetadata(Connection connection, String tableName)
  2. getTableNames(Connection conn)
  3. getTableNames(DatabaseMetaData dbMD)
  4. isDB2(DatabaseMetaData metadata)
  5. isDerbyDatabase(DatabaseMetaData metaData)
  6. isIdGenerated(DatabaseMetaData metaData)
  7. isMysql(DatabaseMetaData metadata)
  8. isOracleForSid(DatabaseMetaData metadata, String oracleProduct)
  9. isSybase(DatabaseMetaData metadata)