You should move that, "getting a connection" code in to factory class which will initialize when the application starts and can be used to get connections.
Here is just a brief guide to get started. You may add many features/functions to enhance or make it more usable later.
And You know how to use this class in client code right ?