Deleting All Rows from a Database Table - Java JDBC

Java examples for JDBC:Table

Description

Deleting All Rows from a Database Table

Demo Code

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

public class Main {
  public void m() throws Exception {
    Connection connection = null;
    Statement stmt = connection.createStatement();

    // Use TRUNCATE
    String sql = "TRUNCATE my_table";

    // Use DELETE
    sql = "DELETE FROM my_table";

    // Execute deletion
    stmt.executeUpdate(sql);/*www  . j  a  v a2 s  . c  o m*/
  }
}

Related Tutorials