aspose file tools*
The moose likes JDBC and the fly likes Q: repeatedly execute() on PreparedStatement without close() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Q: repeatedly execute() on PreparedStatement without close()" Watch "Q: repeatedly execute() on PreparedStatement without close()" New topic
Author

Q: repeatedly execute() on PreparedStatement without close()

Yan Zhou
Ranch Hand

Joined: Sep 02, 2003
Posts: 137
Hi,

I wonder if I can repeatedly call executeUpdate() on a PreparedStatement without closing the statement? Like this:



Would this have problem of leaking resource?

Yan
Annie Smith
Ranch Hand

Joined: Mar 05, 2005
Posts: 172
Yes, it might.

Oracle, for instance, throws up a runtime exception saying "maximum number of cursors exceeded..."


Cheers!<br /><b>Annie</b>
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14157
    
  19

For updating a number of rows this way, you'd better use addBatch() and executeBatch().

See the API documentation of classes java.sql.PreparedStatement and java.sql.Statement.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
Consider Paul's rocket mass heater.
 
subject: Q: repeatedly execute() on PreparedStatement without close()