This is a basic tutorial intended to showcase best practices for connecting to a SQL database. It will not tell you everything, but it is a good start.
Another assumption is that you will be using HikariCP. A connection pooling library will handle recreating Connections for you in a proper manner, while respecting network timeouts and max lifetime settings.
First make a class to wrap your HikariDataSource: