Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why we require execute() method?

 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok

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

Thanx

Shrinivas
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not really getting what you are saying, can you elaborate more.

Shrinivas
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell me the stored procedure or SQL which may return multiple resultsets.?

Thanx in advance
Shrinivas
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic