File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Statement Reuse? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Statement Reuse?" Watch "Statement Reuse?" New topic

Statement Reuse?

Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210
I would like to know if we can reuse the same Statement object for executing more than one query. Or, should we create a new statement for different queries.

For example,

In the above case, is there any harm in using the same statement st1 for both the executeUpdate() queries?

SCJP 1.4 85%
aleem khan
Ranch Hand

Joined: Aug 07, 2008
Posts: 94
Yes you can use the same statement object, after all it is just as instance of class Connection. And with that instance you are invoking the method executeUpdate(). If it behaves differently then the basic OO Concepts itself is incorrect

SCJP(1.4), SCWCD, Oracle 9i SQL certified, Oracle PLSQL Developer Certified Associate
aleem khan
Ranch Hand

Joined: Aug 07, 2008
Posts: 94
sorry typo mistake, it is "not instance of Connection" , it is of type Statement
I agree. Here's the link:
subject: Statement Reuse?
It's not a secret anymore!