• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between execute() and excuteQuery()

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i tried to know the difference between execute() and executeQuery(). but i'm unalbe to know. if any one knows about this pls reply.

Thank U.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
execute() is a generic method which can be called for retrieving data from the database as well updating the database. However it is never going to return you the ResultSet in case of retrieval or the number of rows updated in case of update/delete/insert. You might want to use it in places where you just want to test if the database access is a success or not.

On the other hand, executeQuery is very specific to retrieval of data from the database. It returns you a ResultSet which can be used to pull the data you need.

Also, The executeQuery() method takes a precompiled SQL statement as parameter and executes it.

Whereas, the execute() method simply executes an SQL statement without prior knowledge of the type of statement.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually the execute() method does return a ResultSet, if the SQL produces one. And it returns an update count, too, if the SQL produces one. From the documentation:

The execute method executes an SQL statement and indicates the form of the first result. You must then use the methods getResultSet or getUpdateCount to retrieve the result, and getMoreResults to move to any subsequent result(s).

Incidentally, the documentation is the answer to the original question.
reply
    Bookmark Topic Watch Topic
  • New Topic