It's not a secret anymore!
The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "Difference between execute() and executeQuery()" Watch "Difference between execute() and executeQuery()" New topic

Difference between execute() and executeQuery()

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 751
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
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

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] [About Bear] [Books by Bear]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Difference between execute() and executeQuery()
It's not a secret anymore!