Java SQL Table hasTable(Connection conn, String schemaName, String tableName)

Here you can find the source of hasTable(Connection conn, String schemaName, String tableName)

Description

has Table

License

Apache License

Declaration

public static boolean hasTable(Connection conn, String schemaName,
            String tableName) 

Method Source Code

//package com.java2s;
/*/*  w  ww  . j a v  a  2  s.c  o m*/
 * Copyright 2015, Yahoo Inc.
 * Copyrights licensed under the Apache License.
 * See the accompanying LICENSE file for terms.
 */

import java.sql.Connection;

import java.sql.ResultSet;
import java.sql.Statement;

public class Main {
    public static boolean hasTable(Connection conn, String schemaName,
            String tableName) {
        ResultSet rs = null;
        try {
            rs = conn.getMetaData().getTables(null, schemaName,
                    tableName.toUpperCase(), null);
            while (rs.next()) {
                if (tableName.equalsIgnoreCase(rs.getString("TABLE_NAME")))
                    return true;
            }
        } catch (Exception ex) {
        } finally {
            if (rs != null)
                try {
                    rs.close();
                    rs = null;
                } catch (Exception iex) {
                }
        }
        return false;
    }

    public static void close(Statement stmt) {
        if (stmt != null)
            try {
                stmt.close();
            } catch (Exception ex) {
            }
    }

    public static void close(ResultSet rs) {
        if (rs != null)
            try {
                rs.close();
            } catch (Exception ex) {
            }
    }

    public static void close(Connection conn) {
        if (conn != null)
            try {
                conn.close();
            } catch (Exception ex) {
            }
    }
}

Related

  1. getTables(Connection connection)
  2. getTablesFromDatabase(Connection conn)
  3. getTableSize(Connection conn, String tableName)
  4. getTableSize(final Statement statement, final String schema, final String table, boolean scope)
  5. getTotalRows(String tableName, Statement statement)
  6. hasTable(String TableName, Connection conn)
  7. isExistsDerbyTable(Connection derbyConnection, String schema, String table)
  8. isFileImportable(File file, String prefix)
  9. isTableEmpty(Connection con, String schemaName, String tableName)