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 why we require execute() method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "why we require execute() method?" Watch "why we require execute() method?" New topic
Author

why we require execute() method?

Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Hello Friends,
Can anybody tell me why we require execute method?, How it can be used for multiple resultsets?, If anybody can give me some real world example details i will be highly obliged.


thanx in advance
Shrinivas
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
Hi,

You really need to provide us with more information. Which execute method are you talking about - on a Statement?

What are you trying to do with multiple ResultSets?

If you provide more information, then maybe someone can help.
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Ok

execute() method of Statement is what i am talking about.

Thanx

Shrinivas
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30294
    
150

Shrinivas,
The execute method tells the database you are ready to run the query. You can only have one resultset open at a time for a given statement. So you can either close the resultset before running the next query or having multiple statement objects.


[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
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
I am not really getting what you are saying, can you elaborate more.

Shrinivas
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

From the java API's:

"Executes the given SQL statement, which may return multiple results. In some (uncommon) situations, a single SQL statement may return multiple result sets and/or update counts. Normally you can ignore this unless you are (1) executing a stored procedure that you know may return multiple results or (2) you are dynamically executing an unknown SQL string.
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). "

Pretty self explanatory!

Jamie
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Can you tell me the stored procedure or SQL which may return multiple resultsets.?

Thanx in advance
Shrinivas
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30294
    
150

Shrinivas,
You can write a stored procedure that does multiple queries. For example,

These get returned as two result sets from the stored procedure.
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Hello
Thanx a lot, one more thing is in Sybase database i can fire a multiple select queries as a single batch by seprating them by "\n"(sql query is treated as one query). Thats what i have understood while i was going through one book (Java Enterprise in a Nutshell--Oreilly), if possible give me some extra inputs.

Thanx one more time
Shrinivas
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30294
    
150

Shrinivas,
I've done that using a stored proc in Sybase. I have never tried separating queries by newline characters in a regular statement, so I can't say whether that works.

However, I wouldn't recommend it. Having database specific code in a stored proc is one thing. Having it embedded in Java code is a bigger migration issue if you ever wish to switch databases.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why we require execute() method?