• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it might.

Oracle, for instance, throws up a runtime exception saying "maximum number of cursors exceeded..."
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15278
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic