Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7504231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:30:18+00:00 2026-05-29T21:30:18+00:00

I have one application in which I need to delete table if exit in

  • 0

I have one application in which I need to delete table if exit in Microsoft Access Database.
I saw the code here. The table name which I want to delete is data_table and the access database file name is local_entry
so where I need to change the code so it work for my application.

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 < 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();
    }
}

I think I need to change this two line:

String dropTable = "DROP TABLE ";
String[] tables = DB_TABLE;

can I change DROP TABLE to data_table and what about second line. What is this DB_TABLE
I change the whole code by this way but till problem is there:

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 < 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();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:30:20+00:00Added an answer on May 29, 2026 at 9:30 pm

    try this code

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:MsAccessDSN");
    Statement stmt = con.createStatement();
    // Specify the type of object; in this case we want tables
    String[] types = {"TABLE"};
    ResultSet checkTable = con.getMetaData().getTables(null, null, "%", types);
    String tableName = null;
    
    while (checkTable.next())
    {
        System.out.println("In here");
        tableName = checkTable.getString(3)
        System.out.println(tableName);
    
        // check if the table 'data_table' exist in your database
        if (tableName.equals("data_table"){    
            try {
                //drop the table if present  
                int temp = stmt.executeUpdate("DROP TABLE " + tableName);
                break;
            }
            catch (Exception e) {
                System.err.println("Exception in testDropTable (): \n"
                    + "Drop Table testDropTable threw an exception: " +(e.getMessage()));
            }
        }    
    }
    con.close; 
    

    for more information visit here Metadata

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Folks, I have one application to develop in which I need notification when the
I have a couple of pre-existing applications which I need to run in one
I have one application which uses the standard .NET forms authentication cookie, now I
I have an application which may only have one instance of itself open at
The problem: we have one application that has a portion which is used by
My application is viewbased application in which I have one button. On click of
I have an application which obtains data in JSON format from one of our
I have a Java application which requires certain software (one of them being Perl)
I have a one page web application, which means alot of javascript. External scripts
Hai every one I am developing an windows application in which i have to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.