• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using executeQuery to update data - performance issues?

 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can someone please tell me if there are any performance issues while using executeQuery to update data using JDBC or is it better to use executeUpdate?

 
Jan Cumps
Bartender
Posts: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No performance issues known. You can check the javadoc of both methods to see how they are different.
But I would be surprised if the use of executeQuery would be the cause of your performance issues (if you have any issues).

Regards, Jan
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somnath Mallick wrote:Hi,

Can someone please tell me if there are any performance issues while using executeQuery to update data using JDBC or is it better to use executeUpdate?




executeQuery() returns the resultset,so whatever data we are updating it will returns it.

but as we know when we are using executeUpdate() then it will return int which says that whether the data is updated or not.
if it return 0 that means data is not updated but if it return 1 it means data is updated.
so there is performance issue....as executeQuery have to return the whole resultset Updated.

As we have to only know whether the data is updated or not,so it will be better if we use executeUpdate while running update command.....
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somnath Mallick wrote:Hi,

Can someone please tell me if there are any performance issues while using executeQuery to update data using JDBC or is it better to use executeUpdate?

[/quote

executeQuery -> If you want to return ResultSet.
executeUpdate -> If you want to insert the data and make sure whether its successfully inserted or not.

Two has its own use. So dont confuse with that.
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets say, we are not concerned with the return value, just updating, inserting or deleting a table is the main concern. Then a ResultSet should be more of a burden on resources, wouldn't it?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34863
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More importantly, executeUpdate is meant for updates. executeQuery is not. You should the clearer one anyone.
 
sonia arora
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
executeQuery should be used with select command.
with update, insert, delete use executeUpdate because otherwise a exception is raised :
"No Result Set was produced"
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:You should the clearer one anyone.

Didn't understand this part!

I have a code which i was reviewing, it had update, insert with executeQuery, and its a working code. So just was intrigued to know that is it the correct way because the code is working!
 
sonia arora
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the code may work any way.
but the correct way to update or insert is to use executeUpdate().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic