HSQLDB Tutorial on HSQLDB Delete Clause

whenever you want to delete a record from any hsqldb table, you can use the delete from command.

syntax

here is the generic syntax for delete command to delete data from a hsqldb table.

delete from table_name [where clause]
  • if where clause is not specified, then all the records will be deleted from the given mysql table.

  • you can specify any condition using where clause.

  • you can delete records in a single table at a time.

example

let us consider an example that deletes the record data from the table named tutorials_tbl having id 105. following is the query that implements the given example.

delete from tutorials_tbl where id = 105;

after execution of the above query, you will receive the following output −

(1) rows effected

hsqldb – jdbc program

here is the jdbc program that implements the given example. save the following program into deletequery.java.

import java.sql.connection;
import java.sql.drivermanager;
import java.sql.statement;

public class deletequery {
   
   public static void main(string[] args) {
      connection con = null;
      statement stmt = null;
      int result = 0;
      
      try {
         class.forname("org.hsqldb.jdbc.jdbcdriver");
         con = drivermanager.getconnection(
            "jdbc:hsqldb:hsql://localhost/testdb", "sa", "");
         stmt = con.createstatement();
         result = stmt.executeupdate(
            "delete from tutorials_tbl   where id=105");
      } catch (exception e) {
      
         e.printstacktrace(system.out);
      }
      system.out.println(result+" rows effected");
   }
}

you can start the database using the following command.

\>cd c:\hsqldb-2.3.4\hsqldb
hsqldb>java -classpath lib/hsqldb.jar org.hsqldb.server.server --database.0
file:hsqldb/demodb --dbname.0 testdb

compile and execute the above program using the following command.

\>javac deletequery.java
\>java deletequery

after execution of the above command, you will receive the following output −

1 rows effected