![]() |
VOOZH | about |
The UPDATE operation modifies existing records in a table, usually with a WHERE clause to target specific rows. Without it, all records may be updated. The DELETE operation removes records from a table, also typically using a WHERE clause. Omitting it deletes all rows in the table.
Create a simple register table
Update Operation in JDBC involves loading the driver, connecting to the database, preparing an UPDATE query with PreparedStatement, setting parameters, and executing it using executeUpdate(). It returns the number of affected rows to determine success. Exception handling and resource cleanup are essential.
UPDATE table_name SET column1 = value1 WHERE condition;
In JDBC, the Update operation is used to change current entries in a database table using SQL UPDATE statements.
Example: The following example updates the city column for a user in the register table based on their email ID.
App.java:
Output:
Delete Operation in JDBC follows the usual steps: load the driver, connect to the database, prepare a DELETE query with PreparedStatement, set parameters, and execute using executeUpdate(). It returns the number of rows deleted. Always close resources properly.
DELETE FROM table_name WHERE condition;
In JDBC, the Delete operation is used to delete current entries in a database table using SQL DELETE statements.
This example deletes a specific user from the register table based on their email.
App.java:
Output:
Explanation: