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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 136
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: 13869
    
  10

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Q: repeatedly execute() on PreparedStatement without close()
 
Similar Threads
Java - Mysql connectivity
MSAccess and JDBC
Any Possibilities to get other than SQLException while using executeUpdate() method
Weird number been put to DB table through JDBC
Auto Increment ID Field Table in the Oracle Database