Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / November 2003

Tip: Looking for answers? Try searching our database.

Using statement.execute more than once at the same statement

Thread view: 
Xnedra - 24 Nov 2003 13:31 GMT
Hi there,

i am starting using jdbc these days. My first tests use something
like:

Statement stat = connection.getStatement();
stat.execute("SELECT * FROM customer");
handleResult(stat.getResultSet());
stat.execute("SELECT * FROM employees";
handleResult(stat.getResultSet());

..and they work.

I have two questions:
1) When i had a look at some tutorials at sun.com i found out, that
all executions use executequery or executeupdate.... never the pure
execute is used.
Is there a special reason for this?

2) In my testapplication i could use the same statement more than
once. Is there a reason why one should create new statements for each
query? And why is there no exception thrown when i try to use it
twice?

Thanks for any answer. :)

K.Stamme
Christophe Vanfleteren - 24 Nov 2003 14:13 GMT
> Hi there,
>
[quoted text clipped - 14 lines]
> execute is used.
> Is there a special reason for this?

Look at the return values of those specific methods. You'll see what they are
good for.

> 2) In my testapplication i could use the same statement more than
> once. Is there a reason why one should create new statements for each
> query? And why is there no exception thrown when i try to use it
> twice?

No, you don't have to create new Statements every time.

But if you're repeatedly using the same Statement, you'd better use a
PreparedStatement (it can be handled more efficiently by the database),
which better to work with anyway once you have to pass arguments to your
query.

Signature

Regards,
Christophe Vanfleteren



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.