Java SQL Table Exist tableExists(Statement stmt, String name)

Here you can find the source of tableExists(Statement stmt, String name)

Description

table Exists

License

Open Source License

Declaration

public static boolean tableExists(Statement stmt, String name) throws SQLException 

Method Source Code


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

import java.sql.*;

public class Main {
    public static boolean tableExists(Statement stmt, String name) throws SQLException {

        ResultSet rs = stmt.executeQuery("SELECT count(*) FROM sqlite_master WHERE type == 'table' and name == '"
                + name.replace("'", "''") + "';");
        rs.next();/*from   w w  w. jav a2 s  . c om*/
        return (0 == rs.getInt("count(*)")) ? (false) : (true);

        /*
        return stmt.executeQuery(
           "SELECT\n" +
           "   CASE\n" +
           "      WHEN EXISTS(SELECT 1 FROM sqlite_master WHERE type == 'table' and name == '" + name.replace("'", "''") + "')\n" +
           "         THEN 1\n" +
           "      ELSE 0\n" +
           "   END AS 'exists'\n" +
           ";"
        ).getBoolean("exists");
        */

    }
}

Related

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