Java JDBC MySQL Connection deleteTableData(String tableName)

Here you can find the source of deleteTableData(String tableName)

Description

delete Table Data

License

Open Source License

Declaration

public static void deleteTableData(String tableName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class Main {
    public static void deleteTableData(String tableName) {
        try {//from   ww  w  .  ja v a2 s.  co  m
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/harddiskbrowser", "root",
                    "root");

            String queryDelete = " delete from " + tableName;
            PreparedStatement deletingStatement = con.prepareStatement(queryDelete);
            deletingStatement.execute();

            con.close();
        } catch (Exception e) {
            System.out.println("Exception occurred in deleteTableData()" + e);
        }
    }
}

Related

  1. createConnection()
  2. createConnection(String hostname, String port, String database, String username, String password)
  3. createConnection(String url, String user, String password)
  4. createConnectionUtf8(String connString)
  5. createTable(String dbFile, String tableName, String tableDefinition)
  6. getAllNames()
  7. getConnection()
  8. getConnection()
  9. getConnection()