Java SQL Table dropTable(String tableName, Connection con)

Here you can find the source of dropTable(String tableName, Connection con)

Description

drop Table

License

Apache License

Declaration

public static void dropTable(String tableName, Connection con) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.Connection;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import java.util.List;

public class Main {
    public static void dropTable(String tableName, Connection con) throws SQLException {
        tableName = normalizeTableName(tableName, con);
        con.createStatement().execute("drop table " + tableName);

    }/*w  w w  . ja  v  a 2 s  .c  o m*/

    public static String normalizeTableName(String table, Connection con) throws SQLException {
        for (String t : getTables(con)) {
            if (t.equalsIgnoreCase(table)) {
                return t;
            }
        }
        return table;
    }

    public static List<String> getTables(Connection con) throws SQLException {
        String[] types = { "TABLE" };
        ResultSet rs = con.getMetaData().getTables(null, null, "%", types);
        List<String> tables = new ArrayList<String>();
        while (rs.next()) {
            tables.add(rs.getString("TABLE_NAME"));
        }
        rs.close();
        return tables;

    }
}

Related

  1. createSourceTable(Connection con)
  2. createTable(Connection dbCon, String tableName, String fields)
  3. createTable(Statement statement, String spaceName, String minSeeders, String capacity, String replicationCount)
  4. createTable(String createTblSql, Connection conn)
  5. createTableAndInsertData(Connection c)
  6. dumpTable(Connection conn, String TableName, PrintWriter out)
  7. dumpTable(Connection connection, String tablename)
  8. dumpTableToFile(Connection con, String table, String fileName)
  9. exportTableData(String tableName, Connection con)