I agree with @Turing85, this is not a good practice. However, if you're building a tool to assist with database analysis, such as measuring query performance or automating some non-business-related analyses, I think you simply need to use something like DataSourceFactory, JdbcTemplate. This will allow you to dynamically connect to databases using data provided, for example, through an endpoint.