Java JDBC Connection Create clearTable(String tableName, String driver, String url, String user, String password)

Here you can find the source of clearTable(String tableName, String driver, String url, String user, String password)

Description

clear Table

License

LGPL

Declaration

public static void clearTable(String tableName, String driver, String url, String user, String password) 

Method Source Code


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

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    public static void clearTable(String tableName, String driver, String url, String user, String password) {
        Connection conn = null;/*from w ww . jav a2s.c  o m*/
        Statement stmt = null;
        try {
            Class.forName(driver);

            conn = DriverManager.getConnection(url, user, password);
            stmt = conn.createStatement();
            String sql = "DELETE FROM " + tableName;
            stmt.executeUpdate(sql);
            System.out.println("All record in " + tableName + " deleted");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (stmt != null)
                    stmt.close();
            } catch (SQLException se) {
                se.printStackTrace();
            }
            try {
                if (conn != null)
                    conn.close();
            } catch (SQLException se) {
                se.printStackTrace();
            }
        }
    }
}

Related

  1. canConnect(Properties dbSettings)
  2. createConnection()
  3. createConnection(Properties props, String prefix)
  4. createDatabase(String dbConnectionString, String dbName, String user, String pass, String driver)
  5. createDbConnection(String dbUrl, String dbUser, String dbPass, String dbDriverClass)