File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Using executeQuery to update data - performance issues? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Using executeQuery to update data - performance issues?" Watch "Using executeQuery to update data - performance issues?" New topic
Author

Using executeQuery to update data - performance issues?

Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
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: 2503
    
    8

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 and ITIL foundation
youtube channel
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

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: 477
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

Joined: May 26, 2003
Posts: 30762
    
156

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: 477
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().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using executeQuery to update data - performance issues?