The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.sql  [73 examples] > Deleting Data  [2 examples]

e263. Deleting All Rows from a Database Table

All the rows in a table can be deleted either by using the TRUNCATE or DELETE SQL statement. TRUNCATE is faster than DELETE since it does not generate rollback information, does not fire any delete trigger, and does not record any information.

This example deletes all the rows from a database table called my_table.

    try {
        Statement stmt = connection.createStatement();
    
        // Use TRUNCATE
        String sql = "TRUNCATE my_table";
    
        // Use DELETE
        sql = "DELETE FROM my_table";
    
        // Execute deletion
        stmt.executeUpdate(sql);
    } catch (SQLException e) {
    }

 Related Examples
e262. Deleting a Row from a Database Table

See also: Batching    Connections    Database Meta Data    Drivers    Importing and Exporting    Inserting and Updating Data    Oracle OBJECTs    Oracle VARRAYs    Procedures and Functions    Retrieving Data    Scrollable Result Sets    Tables    Updatable Result Sets   


© 2002 Addison-Wesley.