| Author |
Using executeQuery to update data - performance issues?
|
Somnath Mallick
Ranch Hand
Joined: Mar 04, 2009
Posts: 471
|
|
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
Joined: Dec 20, 2006
Posts: 2343
|
|
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
|
OCUP UML fundamental
ITIL foundation
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1046
|
|
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.....
|
SCJP6.0,My blog Ranchers from Delhi
|
 |
Rajkumar balakrishnan
Ranch Hand
Joined: May 29, 2008
Posts: 445
|
|
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.
|
Never try to be a hard-worker. Be a smart-worker.
My Blog
|
 |
Somnath Mallick
Ranch Hand
Joined: Mar 04, 2009
Posts: 471
|
|
|
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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26184
|
|
|
More importantly, executeUpdate is meant for updates. executeQuery is not. You should the clearer one anyone.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
sonia arora
Ranch Hand
Joined: Mar 10, 2010
Posts: 31
|
|
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
Joined: Mar 04, 2009
Posts: 471
|
|
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
Joined: Mar 10, 2010
Posts: 31
|
|
the code may work any way.
but the correct way to update or insert is to use executeUpdate().
|
 |
 |
|
|
subject: Using executeQuery to update data - performance issues?
|
|
|