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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply 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
Bartender

Joined: Aug 16, 2005
Posts: 12909
    
    3

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
Auto Increment ID Field Table in the Oracle Database
Any Possibilities to get other than SQLException while using executeUpdate() method
Java - Mysql connectivity
Weird number been put to DB table through JDBC
MSAccess and JDBC