Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
JDBC and Relational Databases
Q: repeatedly execute() on PreparedStatement without close()
Yan Zhou
Ranch Hand
Posts: 137
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I wonder if I can repeatedly call executeUpdate() on a PreparedStatement without closing the statement? Like this:
stmt = con.prepareStatement(INSERT_SQL); stmt.setString(1, value); if (condition1IsMet) stmt.setInt(2, value2); stmt.executeUpdate(); // execute() } Collection list = getIds(); if (list != null) { Iterator i = list.iterator(); while (i.hasNext()) { stmt.setInt(2, anotherValue); stmt.executeUpdate(); // execute many times } } stmt.close(); // close at end
Would this have problem of leaking resource?
Yan
Annie Smith
Ranch Hand
Posts: 172
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 16084
88
I like...
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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.
Jesper's Blog
-
Pluralsight Author Page
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Auto Increment ID Field Table in the Oracle Database
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
More...