private ConnectionProvider buildConnectionProvider(String dbName) { Properties props = new Properties( null ); props.put( "hibernate.connection.driver_class", DRIVER ); // Inject dbName into connection url string. props.put( "hibernate.connection.url", String.format( URL, dbName ) ); props.put( "hibernate.connection.username", USER ); props.put( "hibernate.connection.password", PASS ); // Note that DriverManagerConnectionProviderImpl is an internal class. However, rather than creating // a ConnectionProvider, I'm using it for simplicity's sake. // DriverManagerConnectionProviderImpl obtains a Connection through the JDBC Driver#connect DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl(); connectionProvider.configure( props ); return connectionProvider; }