Quantcast
Channel: MySQL Forums - Connector/J, JDBC and Java
Viewing all articles
Browse latest Browse all 884

Persistent connection or per-request? (no replies)

$
0
0
Hi,

My java application calls some stored procedures and some of these procedures use LAST_INSERT_ID(). The application creates a connection at startup and destroys the connection when it shuts down.

I was thinking, however, that if it were multi-threaded and some of the stored procedures were being called almost simultaneously, then the last_insert_id() could retrieve the wrong value as both calls to the stored procedure would be on the same connection.

Is this right? And if so, how do people get around this? I'm hesitant to using a new connection everytime i want to interact with the database as I believe creating connections are far more expensive and slower than anything else with regards to interacting with the database.

Thanks!

Viewing all articles
Browse latest Browse all 884

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>