1

I wrote these lines of java code to empty my application tables, but after the execution nothing happens.

Class.forName("org.hsqldb.jdbc.JDBCDriver"); 
Connection con = DriverManager.getConnection("jdbc:hsqldb:file:ordini", "root", "root");
Statement stmt = con.createStatement();
if(ORDINI) stmt.executeUpdate("DELETE FROM ordini");
if(ORDINI_HISTORY) stmt.executeUpdate("DELETE FROM ordini_history");
if(PRODOTTI) stmt.executeUpdate("DELETE FROM prodotti");

I've already tried with TRUNCATE TABLE statement but is the same thing.

alf_red
  • 112
  • 1
  • 14
  • 1
    Do you commit your connection? Or is autocommit set to true? – JB Nizet Apr 29 '12 at 14:43
  • No I didn't set the auto-commit connection property, but i tried to execute "con.commit()" at the end of the code... but the tables are still not empty. – alf_red Apr 29 '12 at 14:49
  • Maybe you're looking at a file different from the file used by the code, or maybe all three flags are false. Try debugging your code, and using an absolute file path instead of a relative one. – JB Nizet Apr 29 '12 at 14:54
  • seems like your if condition gives false. ;) kindly place full code snippet. – Subhrajyoti Majumder Apr 29 '12 at 15:31

2 Answers2

0

It seems your program exits immediately after exectuting the statements. It should work if you add this line to the end:

stmt.executeUpdate("SHUTDOWN");
fredt
  • 24,044
  • 3
  • 40
  • 61
0

Use executeUpdate("TRUNCATE SCHEMA public AND COMMIT") as answered here: How can I wipe data from my HSQLDB after every test?

Community
  • 1
  • 1