File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Difference between execute() and executeQuery() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply 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: 56172
    
  13

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 ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26168
    
  66

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Difference between execute() and executeQuery()
 
Similar Threads
a easy question please help !!!
reusing the Statement object
jdbc connection and query execution
using data base Access
Invalid Transaction State