This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
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
jQuery in Action, 3rd edition
subject: Statement Reuse?
It's not a secret anymore!