Which method is used to execute a SQL INSERT, UPDATE, or DELETE query in JDBC?

Which method is used to execute a SQL INSERT, UPDATE, or DELETE query in JDBC?

a) executeQuery()
b) executeUpdate()
c) execute()
d) executeModify()

Answer:

b) executeUpdate()

Explanation:

The executeUpdate() method in JDBC is used to execute SQL queries that modify the database, such as INSERT, UPDATE, or DELETE operations. Unlike executeQuery(), which is used for retrieving data, executeUpdate() is designed for queries that change the data or structure of the database. This method returns an integer representing the number of rows affected by the query.

Using executeUpdate() is straightforward and effective for operations that involve data manipulation. For example, when inserting new records into a table, updating existing records, or deleting records, executeUpdate() provides a simple way to perform these actions and obtain feedback on the number of affected rows.

Understanding the distinction between executeUpdate() and other JDBC methods is essential for correctly implementing database operations in Java applications. This method is a key tool for maintaining and modifying the state of the database, making it an integral part of JDBC programming.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top