• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reuse of same object within single transaction

 
Tommy Griffith
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I was just wondering as my testing seems to show it's ok but I'd like to confirm it. Could you declare a single callablestatement object at the start of the code...


then reuse it after each execute()? That should be ok, right? as each execute() in the transaction goes into jvm memory (surmising)? I'd hate to have to declare multiple CallableStatements. As I said, my testing seems ok with it but I'm not sure. Thank you.
 
Paul Clapham
Sheriff
Posts: 21557
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code doesn't create a single CallableStatement object. It does declare a single CallableStatement variable, but then it creates three CallableStatement objects and assigns each of them (one at a time) to the single variable.

It's true that each of the three objects gets put into memory (there's no other place to put objects anyway) but that shouldn't be a big deal, since you've got tons of memory compared to what's required for a CallableStatement object. However you should make sure that you call close() on each of the three objects before you abandon them to be found later by the garbage collector, otherwise your database might have open resources which it has to clean up later after it notices they aren't being used any more.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic