Java Utililty Methods SQL Table Exist

List of utility methods to do SQL Table Exist

  1. HOME
  2. Java
  3. S
  4. SQL Table Exist

Description

The list of methods to do SQL Table Exist are organized into topic(s).

Method

boolean tableExist(Statement stmt, String tablename)
table Exist
ResultSet result = null;
try {
 result = stmt
 .executeQuery("select count(*) from sqlite_master where type='table' and name = 'develop'");
 while (result.next()) {
 if (result.getInt(1) == 1) {
 return true;
} catch (SQLException e) {
 e.printStackTrace();
} finally {
 if (result != null) {
 try {
 result.close();
 } catch (SQLException e) {
 e.printStackTrace();
return false;
boolean tableExists(Connection con, String table)
table Exists
try {
 con.createStatement().execute("select * from " + table);
 return true;
} catch (SQLException e) {
 return false;
boolean tableExists(Connection con, String tableName)
Tests if a table exists in the database
if (tableName == null) {
 throw new NullPointerException("tableName cannot be null");
ResultSet res = con.getMetaData().getTables(null, null, null, new String[] { "TABLE" });
while (res.next()) {
 if (res.getString(3).equalsIgnoreCase(tableName) && "TABLE".equals(res.getString(4))) {
 return true;
return false;
boolean tableExists(Connection conn, String name)
Returns true if the table with the specified name exists, false if it does not.
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;
boolean tableExists(Connection conn, String tableName)
table Exists
try (Statement stmt = conn.createStatement()) {
 stmt.executeQuery("select * from " + tableName + " where 1=0");
 return true;
} catch (Exception e) {
 return false;
boolean tableExists(java.sql.Connection conn, java.lang.String table)
Returns true if the table already exists in the JDBC database.
throw new RuntimeException();
boolean tableExists(Statement stmt, String name)
table Exists
ResultSet rs = stmt.executeQuery("SELECT count(*) FROM sqlite_master WHERE type == 'table' and name == '"
 + name.replace("'", "''") + "';");
rs.next();
return (0 == rs.getInt("count(*)")) ? (false) : (true);


AltStyle によって変換されたページ (->オリジナル) /