title: delete table if exists in Microsoft Access
body: <p>I have one application in which I need to delete table if exit in Microsoft Access Database.
  I saw the code <a href="http://p2p.wrox.com/java-databases/32033-newbie-question-check-if-table-exists-db.html#post281527" rel="nofollow">here</a>. The table name which I want to delete is <strong>data_table</strong> and the access database file name is <strong>local_entry</strong>
  so where I need to change the code so it work for my application.</p>
  
  <pre><code>public void testDropTable () throws SQLException{
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection con = DriverManager.getConnection("jdbc:odbc:MsAccessDSN");
      Statement stmt = con.createStatement();
      ResultSet checkTable = con.getMetaData().getTables(null, null, "POI", null);
      String tableName = null;
      while (checkTable.next())
      {
          System.out.println("In here");
          tableName = checkTable.getString("TABLE_NAME");
          System.out.println(tableName);
      }
      if (tableName != null){
          try {
              String dropTable = "DROP TABLE ";
              String[] tables = DB_TABLE;
              for (int i = 0; i &lt; tables.length; i++){
                  String stringCode = new String();
                  stringCode = stringCode + tables[i];
                  System.out.println(dropTable + tables[i]);
  
                  // Drop each table in the array.
                  int temp = stmt.executeUpdate(dropTable + tables[i]);
              }
          }
          catch (Exception e) {
              System.err.println("Exception in testDropTable (): \n"
                      + "Drop Table testDropTable threw an exception: " +(e.getMessage()));
          }
      }
      else{
          con.close();
      }
  }
  </code></pre>
  
  <p>I think I need to change this two line:</p>
  
  <pre><code>String dropTable = "DROP TABLE ";
  String[] tables = DB_TABLE;
  </code></pre>
  
  <p>can I change <strong>DROP TABLE</strong> to <strong>data_table</strong> and what about second line. What is this <strong>DB_TABLE</strong>
  I change the whole code by this way but till problem is there:</p>
  
  <pre><code>public void testDropTable () throws SQLException{
      try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      } catch (ClassNotFoundException e1) {
          e1.printStackTrace();
      }
      Connection con = DriverManager.getConnection("jdbc:odbc:MsAccessDSN");
      Statement stmt = con.createStatement();
      ResultSet checkTable = con.getMetaData().getTables(null, null, "POI", null);
      String tableName = null;
      while (checkTable.next())
      {
          System.out.println("In here");
          tableName = checkTable.getString("data_table");
          System.out.println(tableName);
      }
      if (tableName != null){
          try {
              String dropTable = "DROP TABLE ";
              String[] tables = {"data_table"};
              for (int i = 0; i &lt; tables.length; i++){
                  String stringCode = new String();
                  stringCode = stringCode + tables[i];
                  System.out.println(dropTable + tables[i]);
  
                  // Drop each table in the array.
                  int temp = stmt.executeUpdate(dropTable + tables[i]);
              }
          }
          catch (Exception e) {
              System.err.println("Exception in testDropTable (): \n"
                      + "Drop Table testDropTable threw an exception: " +(e.getMessage()));
          }
      }
      else{
          con.close();
      }
  }
  </code></pre>