Java JDBC Database Metadata tableExists(Connection connection, String tableName)

Here you can find the source of tableExists(Connection connection, String tableName)

Description

table Exists

License

Open Source License

Declaration

public static boolean tableExists(Connection connection,
            String tableName) throws SQLException 

Method Source Code

//package com.java2s;
/*/*  w w w .ja  v a2  s  . co  m*/
 * Copyright (c) Mirth Corporation. All rights reserved.
 * 
 * http://www.mirthcorp.com
 * 
 * The software in this package is published under the terms of the MPL license a copy of which has
 * been included with this distribution in the LICENSE.txt file.
 */

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

public class Main {
    public static boolean tableExists(Connection connection,
            String tableName) throws SQLException {
        ResultSet resultSet = null;

        try {
            DatabaseMetaData metaData = connection.getMetaData();
            resultSet = metaData.getTables(null, null, tableName, null);

            if (resultSet.next()) {
                return true;
            }

            resultSet = metaData.getTables(null, null,
                    tableName.toUpperCase(), null);
            return resultSet.next();
        } finally {
            resultSet.close();
        }
    }
}

Related

  1. printMetaData(Connection con)
  2. printTableExistence(String name, Connection conn)
  3. sequenceExists(String seqName, Connection conn)
  4. tableExists(Connection con, String table)
  5. tableExists(Connection connection, String tableName)
  6. tableExists(DatabaseMetaData metaData, String tableName)
  7. tableExists(String tableName, Connection conn)
  8. tableExists(String tableName, DatabaseMetaData dbm)
  9. tableIsAccesable(Connection conn, String TableName)