a dumb question, if i have a singeton pattern for database connection, is that means if i have 10 request from user, it will have single instance calling or 10 instances ?
a dumb question, if i have a singeton pattern for database connection, is that means if i have 10 request from user, it will have single instance calling or 10 instances ?
thank you !
All 10 request will share a single database connection.
Bad idea. Both the idea of the singleton and keeping the connection open forever are bad idea´s. Singletons are in no way OO and keeping the connection open forever will cause your application to crash when the DB closes the connection because it is opened too long and thus timed out.
Just acquire and close the connection in shortest possible scope. Open it right before creating the statement and close it right after closing the statement. To improve general performance, use connection pooling. If you´re running a web application on an application server, consult the appserver specific documentation how to create datasources. If you´re running a simple client application, look for connection pooling API´s like DBCP, C3P0 and Proxool.