This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 1121

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: 8715
    
    6

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[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: 1121

yowell kum!
Good Luck,
Avi.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: excute methods
 
Similar Threads
Software Life
I Always Wanna Post Java Related Topics
Unregistered?
World Market
WA #2 ..... word association