How to update data into a Table of SQLite database using java

How to Update Data into SQLite Database Using Java Programming

This is the fourth article of the java database tutorial series. The full list of all article under this series can be found at the bottom of this article.

This article is going to demonstrate how to update data into an SQLite database using Java.

Learning how to update data into SQLite Database is very vital for your application, especially developing management systems.

We are going to use the following table to update data into the SQLite database using Java Programming Language.

How to update data into a Table of SQLite database using java

I have already written articles on how to create this kind of database and table.

We are going to update data where email is eunice@test.com kindly have a look at the table above

The following code illustrates how to update a table of SQLite Database using Java Programing language

private static void updateFirstName() {
    // we will update only first name of a certain row
    Connection con = DbConnection.connect(); 
    PreparedStatement ps = null; 
    try {
      String sql = "UPDATE users set firstName = ? WHERE email = ? ";
      ps = con.prepareStatement(sql); 
      ps.setString(1, "EuniceName2");
      ps.setString(2, "eunice@test.com");
      ps.execute();
      System.out.println("Data has been updated");
    } catch (SQLException e) {
      // TODO: handle exception
      System.out.println(e.toString());
    }
  }





 

Other Tutorials Under this 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