aspose file tools*
The moose likes JDBC and the fly likes excute methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "excute methods" Watch "excute methods" New topic
Author

excute methods

eswar kumar
Ranch Hand

Joined: Oct 20, 2002
Posts: 98
in what situations we use executeUpdate(),executeQuery(),execute()? what is the difference among three?
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Hi Eswar,
Myself, I use "executeQuery()" when I want to SELECT data from the database (i.e. perform a query), I use "executeUpdate()" when I want to INSERT, DELETE or UPDATE (i.e. perform data manipulation) and "execute()" when I want to invoke a database stored procedure.
Hope that helps answer your question.
Good Luck,
Avi.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8964
    
    9

Originally posted by eswar kumar:
what is the difference among three?[/QB]

The difference is in the return type. executeUpdate() returns the number of rows updated. execute() returns a boolean which indicates if a ResultSet is available. executeQuery returns a ResultSet, even if there are no rows returned by the query. I concur with Avi's rules of thumb as to when to use the different methods.


[How To Ask Questions On JavaRanch]
eswar kumar
Ranch Hand

Joined: Oct 20, 2002
Posts: 98
thanQ Joe and Avi now i cleared my doubt
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

yowell kum!
Good Luck,
Avi.
 
jQuery in Action, 2nd edition
 
subject: excute methods