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

Difference between execute() and executeQuery()

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
First of all, I'd like to say many thanks to my fellow ranchers! You've all been so nice to me and have been so generous in helping the likes of me. So what's the difference between the execute() and executeQuery() methods? I tried using executeQuery() to create a database and I get an SQLException error (No result set was produced). Here's my code... Could you also help me pinpoint the problem? Thanks!



SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

executeQuery(), as its name might suggest, is only used for executing queries. That is, SQL SELECT statements.

What sort of result set would expect from a create table statement?
[ October 16, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30913
    
158

Note that there is an executeUpdate() method to call for creates. It doesn't return a resultset because it doesn't apply for any update call.


[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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between execute() and executeQuery()