public boolean tableExists ( String table ) throws SQLException { PreparedStatement statement = null ; ResultSet result = null ; try { statement = this . connection . prepareStatement ( "SHOW TABLES;" ) ; result = execute ( statement ) ; if ( result == null ) { return false ; } boolean found = false ; while ( result . next ( ) ) { if ( table . equalsIgnoreCase ( result . getString ( 1 ) ) ) { found = true ; } } return found ; } finally { if ( statement != null ) { statement . close ( ) ; } if ( result != null ) { result . close ( ) ; } } }
Checks if a specific table exists