Java SQL Table Exist tableExists(Connection conn, String name)

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

Description

Returns true if the table with the specified name exists, false if it does not.

License

Open Source License

Declaration

public static boolean tableExists(Connection conn, String name) throws SQLException 

Method Source Code

//package com.java2s;

import java.sql.Connection;

import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {
    /**//from  w w  w  .  j  a v  a 2 s.  c  o  m
     * Returns true if the table with the specified name exists, false if it does
     * not. <em>Note:</em> the table name is case sensitive.
     */
    public static boolean tableExists(Connection conn, String name) throws SQLException {
        boolean matched = false;
        ResultSet rs = conn.getMetaData().getTables("", "", name, null);
        while (rs.next()) {
            String tname = rs.getString("TABLE_NAME");
            if (name.equals(tname)) {
                matched = true;
            }
        }
        return matched;
    }
}

Related

  1. tableExist(Statement stmt, String tablename)
  2. tableExists(Connection con, String table)
  3. tableExists(Connection con, String tableName)
  4. tableExists(Connection conn, String tableName)
  5. tableExists(java.sql.Connection conn, java.lang.String table)
  6. tableExists(Statement stmt, String name)