Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

excute methods

 
eswar kumar
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in what situations we use executeUpdate(),executeQuery(),execute()? what is the difference among three?
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
eswar kumar
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanQ Joe and Avi now i cleared my doubt
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yowell kum!
Good Luck,
Avi.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic