ADVERTISEMENT
JAVA - How to Delete Data From SQLite Database

SQLite DELETE Syntax using Java Programming

Being the fifth tutorial of Java Database Series, am going to show you how to delete data from SQLite Database using Java.

There are many reasons you would want to delete data from SQLite Database using java, for example, you can give your users functionality to delete their account.

Understanding the DELETE Syntax of an SQLite Database is very vital especially when developing any kind of Management system.

The Following Code is Going to  Illustrate How to DELETE Data From an SQLite Database Table Using Java Programming Language

private static void deleteRow() {
    Connection con = DbConnection.connect(); 
    PreparedStatement ps = null; 
    try {
      String sql = "delete from users WHERE email = ? "; 
      ps = con.prepareStatement(sql); 
      ps.setString(1, "[email protected]");
      ps.execute();
      System.out.println("Data has been deleted!");
    } catch (Exception e) {
      // TODO: handle exception
      System.out.println(e.toString());
    } finally {
      //always remember to close, am forgetting because this is teaching purposes
      try {
        ps.close();
        con.close(); 
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } 
      
      
    }
  }

 

Java Database Tutorial Series

  1. Java Database Connection
  2. How to Insert Data into SQLite database Using Java
  3. The best way to fetch data from SQLite database using Java
  4. How to Update Data Into SQLite Database using Java Programming 
  5. How to delete a row (a record) from SQLite database using Java Programming
  6. How to get the number of rows in an SQLite Database Table Using Java

 



AdBlock Detected!
This site depends on revenue from ad impressions to survive. If you find this site valuable, please consider disabling your ad blocker or pausing adblock for this website.