Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

preparedstatement and loss of connection

 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens to a preparedstatement if the connection is lost and you reconnect? Can you still use a pre-existing preparedstatement, or do you have to recreate it?
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This ultimately depends on the driver, but PreparedStatements are generally tied to the connection, so if you have a different instance of a connection, you most probably need to recreate the statement.

Some connections (again, depending on the driver and/or connection configuration) cache prepared statements, so if you close and recreate it each time, you may actually incur just a small penalty.
 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin Vajsar wrote:This ultimately depends on the driver, but PreparedStatements are generally tied to the connection, so if you have a different instance of a connection, you most probably need to recreate the statement.

Some connections (again, depending on the driver and/or connection configuration) cache prepared statements, so if you close and recreate it each time, you may actually incur just a small penalty.


OK, thanks. I'm dependent on mixed drivers (I guess) because there's more than one db involved and the legacy system is an old one. To be on the safe side, I've written some gets and sets to allow reinitializing the prepared statements from the same helper class that handles the connections. if reconnect then reinitialize ....

re: "I guess" ... I set things up to use Microsoft's jdbc driver version 4 ... did the installation etc. But when connecting to the legacy system, it just didn't work. I had to add the old "Class.forName" statement not required by version 4 and I guess I'm then using a driver that was already installed. Just adding "Class.forName" fixed it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic