Java SQL Table clearTables(Connection connection)

Here you can find the source of clearTables(Connection connection)

Description

Deleting all data from specified table.

License

Open Source License

Parameter

Parameter Description
connection connection to database

Exception

Parameter Description
Exception wrap all exceptions

Declaration

public static void clearTables(Connection connection) throws Exception 

Method Source Code

//package com.java2s;

import java.sql.Connection;
import java.sql.Statement;

public class Main {
    /**/* w  w w .j a  v  a  2s .  co  m*/
     * Deleting all data from specified table.
     *
     * @param connection connection to database
     * @throws Exception wrap all exceptions
     */
    public static void clearTables(Connection connection) throws Exception {
        String[] tables = new String[] { "scorecard_question",
                "scorecard_section", "scorecard_group", "scorecard",
                "scorecard_status_lu", "scorecard_type_lu",
                "scorecard_question_type_lu", "project_category_lu" };

        for (int i = 0; i < tables.length; i++) {
            String query = "DELETE FROM " + tables[i];
            Statement statement = connection.createStatement();
            statement.executeUpdate(query);
        }
    }
}

Related

  1. clearTables(Connection conn)
  2. clearTables(Connection conn, String[] tables)
  3. columnExist(String table, String column, Connection con)
  4. constructObject(Class theClass, Connection db, int objectId, String tableName, String uniqueField)
  5. count(Connection conn, String table)
  6. countTables(Connection connection)