Java JDBC Database Metadata printTableExistence(String name, Connection conn)

Here you can find the source of printTableExistence(String name, Connection conn)

Description

print Table Existence

License

Open Source License

Declaration

public static void printTableExistence(String name, Connection conn) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {
    public static void printTableExistence(String name, Connection conn) throws SQLException {
        if (tableExists(name, conn))
            System.out.println(name + " exists");
        else// w w  w.j av a 2s.c  om
            System.out.println(name + " does not exist");
    }

    public static boolean tableExists(String tableName, Connection conn) throws SQLException {
        DatabaseMetaData dbmd = conn.getMetaData();
        ResultSet rs = dbmd.getTables(null, null, null, null);
        while (rs.next()) {
            if (rs.getString("TABLE_NAME").equalsIgnoreCase(tableName)) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. isOracleForSid(DatabaseMetaData metadata, String oracleProduct)
  2. isSybase(DatabaseMetaData metadata)
  3. isSybaseDb(DatabaseMetaData metaData)
  4. printExistingTables(Connection conn)
  5. printMetaData(Connection con)
  6. sequenceExists(String seqName, Connection conn)
  7. tableExists(Connection con, String table)
  8. tableExists(Connection connection, String tableName)
  9. tableExists(Connection connection, String tableName)