AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using statement.execute more than once at the same statement

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
Xnedra
Guest





PostPosted: Mon Nov 24, 2003 1:31 pm    Post subject: Using statement.execute more than once at the same statement Reply with quote



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
Back to top
Christophe Vanfleteren
Guest





PostPosted: Mon Nov 24, 2003 2:13 pm    Post subject: Re: Using statement.execute more than once at the same state Reply with quote



Xnedra wrote:

Quote:
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?

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

Quote:

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.

--
Regards,
Christophe Vanfleteren

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.