 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Xnedra Guest
|
Posted: Mon Nov 24, 2003 1:31 pm Post subject: Using statement.execute more than once at the same statement |
|
|
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
|
Posted: Mon Nov 24, 2003 2:13 pm Post subject: Re: Using statement.execute more than once at the same state |
|
|
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 |
|
 |
|
|
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
|
|