java - Is it resource-safely to use prepared statements multiple times? -
My application uses some prepared statement in every move of infinity loop. Is it safe to create a prepared position before the loop and to run only pstmt.execute in the loop?
This is also interesting about simple statements.
"infinity loop"? Sorry, it sounds like a bad idea.
People are right when they say that calling a prepared statement several times in the loop is a good idea. But there is a loop with a definite start and end.
I doubt your "infinite loop". It sounds more like a listener that you want to keep alive to respond to some database events.
The answer is "This is okay," but it may be interesting to find out more about what you are doing.
Update after comment:
I have an Atom RSS server that listens for events. When there was a request, I had an RSS listener, who stopped for the service that receives connections from the connections pool, initiate a transaction, prepare the statement prepared in the law field, include the message Let us close the prepared statement, in a block at the end of the law field, make a transaction, and return the connection to the pool.
The JDBC driver or database will cache the cache generated, so it will not be disabled. No need to be hanged on any
No infinite loop. There is no threading problem in this way.
Comments
Post a Comment