GeeCON Prague 2014*
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: 14193
    
  20

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 8 API documentation
 
GeeCON Prague 2014
 
subject: Q: repeatedly execute() on PreparedStatement without close()