Monday 29 April 2013

Difference between execute, executeQuery, executeUpdate & executeBatch



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

9 comments:

  1. execute method is used to execute to obtain multi ResultSet Object

    Java Training in Chennai

    ReplyDelete
  2. i hope to really understand to your information..really execute valuable information...hadoop training in chennai

    ReplyDelete
  3. It was really a wonderful article and I was really impressed by reading this blog. We are giving all software Course Online Training. The HTML5 Courses in Chennai is one of the reputed Training institute in Chennai. They give professional and real time training for all students.

    ReplyDelete
  4. SEO Training in Chennai

    Thanks for sharing this information. SEO is one of the digital marketing techniques which is used to increase website traffic and organic search results. If anyone wants to get SEO Course in Chennai visit FITA Academy located at Chennai. Rated as No.1 SEO Training institute in Chennai.

    ReplyDelete
  5. Nice post. I known some new things from your post. Thanks for sharing.
    primary school website design

    ReplyDelete
  6. After reading your post, i known the difference between the execute, execute query, execute update and execute batch. Thanks you so much for sharing.
    Android training in chennai

    ReplyDelete
  7. My Arcus offer java training with 100% placement. Our java training course that includes fundamentals and advance java training program with high priority jobs. java j2ee training with placement having more exposure in most of the industry nowadays in depth manner of java .

    java training in chennai

    ReplyDelete