Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17



Posted on 1999-07-14
Medium Priority
Last Modified: 2010-04-16
i need to delete all information in my table.  how do i go about doing that?

stmt.executeUpdate("DELETE * FROM TableName");  ???
Question by:capnjazz
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Accepted Solution

rkrenek earned 80 total points
ID: 1246059
You're close. Try:
stmt.executeUpdate("DELETE FROM TableName");
then you can do:
int updates = stmt.getUpdateCount();
to get the number deleted.
If you want to delete specific rows you would add a 'WHERE' clause to the end of your sql statement like:
stmt.executeUpdate("DELETE FROM TableName WHERE column1 = 'something'");


Expert Comment

ID: 1246060

 yes you are correct and after that you have to
 call "commit()" of Connection object.

Author Comment

ID: 1246061
well i had just "DELETE FROM TableName", but it threw an exception?

Author Comment

ID: 1246062
stmt.executeUpdate("DELETE FROM Transmitter");
System.out.println("Deleted Transmitter");

stmt.executeUpdate("INSERT INTO Transmitter VALUES (10, 'Washington Avenue',  'transmitting routine messages', '9,301-464-6824', '12345', '', 'I-279', 'Allegheny', '11', 'dxxxB1C1', '')");
stmt.executeUpdate("INSERT INTO Transmitter VALUES (20, 'Carson Street',      'transmitting routine messages', '9,301-464-3756', '98765', '', 'I-279', 'Allegheny', '11', 'dxxxB1C1', '')");
stmt.executeUpdate("INSERT INTO Transmitter VALUES (40, 'Main Street',        'failed',                        '9,410-922-0090', '68734', 'Transmitter fell down when bionic beaver thought pole was a tree and chewed through it.', 'I-79', 'Butler', '12', 'dxxxB1C2', '07/04/99 08:30')");

i don't get to "Deleted Transmtter".
i checked and i do have one entry in the table.

Expert Comment

ID: 1246063
try {
      boolean status = stmt.execute("DELETE FROM             transmitter");
      if (!status) {
            System.out.println("Deleted Transmitter");
} catch (SQLException e)  {
      System.err.println("SQLExcepton: " + e.getMessage() + ":" +e.getSQLState());

The sql above is correct.
Above will do an update or query, if it was an update it will print "Deleted Transmitter". If there is an error it will print it out. Some problems might be the user that is running this may not be able to delete records from that table. Hope this gets you closer to your problem.


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question