Java SQL Table clearTables(Connection conn, String[] tables)

Here you can find the source of clearTables(Connection conn, String[] tables)

Description

Clear the given tables from the database.

License

Open Source License

Parameter

Parameter Description
conn the Connection to execute.
tables the array of table name to clear.

Exception

Parameter Description
Exception if any error occurs.

Declaration

public static void clearTables(Connection conn, String[] tables)
        throws Exception 

Method Source Code

//package com.java2s;

import java.sql.Connection;

import java.sql.Statement;

public class Main {
    /**//from w w  w . j a  va2 s .c o  m
     * <p>
     * Clear the given tables from the database.
     * </p>
     * @param conn the Connection to execute.
     * @param tables the array of table name to clear.
     * @throws Exception if any error occurs.
     */
    public static void clearTables(Connection conn, String[] tables)
            throws Exception {
        Statement stmt = conn.createStatement();

        try {
            for (int i = 0; i < tables.length; i++) {
                stmt.executeUpdate("DELETE FROM " + tables[i]);
            }
        } finally {
            stmt.close();
        }
    }
}

Related

  1. clearTables(Connection conn)
  2. clearTables(Connection connection)
  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)