Here you can find the source of clearTables(Connection conn, String[] tables)
Clear the given tables from the database.
Parameter | Description |
---|---|
conn | the Connection to execute. |
tables | the array of table name to clear. |
Parameter | Description |
---|---|
Exception | if any error occurs. |
public static void clearTables(Connection conn, String[] tables) throws Exception
//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(); } } }