Use of different execute() methods in JDBC:-
- boolean execute(String SQL) :- It returns a boolean value true if a ResultSet object can be retrieved; otherwise, it returns false. We can use this method to execute SQL DDL statements.
- int executeUpdate(String SQL) : - It returns the no of rows updated in db during the execution of the SQL statement. We can use this method to execute SQL queries like, an INSERT, UPDATE, or DELETE Statement.
- ResultSet executeQuery(String SQL) :- It returns a ResultSet object. We can use this method when we want to execute SELECT queries in db.
- int[] executeBatch() :- JDBC allows a program to perform mutiple insertion or updation of data into database at single step. executeBatch() is responsible to execute batch on statement object.
Advantages of using JDBC batch update:
Using JDBC batch insert or update, we can improve the performance of the application because if we are using batch queries it means we are reducing round-trip towards databse. Thus we are reducing network calls which provides a better performance in application. While using batch insert or update, we should always prefer to use PreparedStatement because this is the best approach to get better performance. We should always prefer to set AutoCommit mode as false
No comments:
Post a Comment