I want to obtain a JdbcTemplate in my Java code. I’ve already got a working java.sql.Connection. To create a new JdbcTemplate it would normally need an instance of the javax.sql.DataSource interface.
Is it somehow possible to obtain a new JdbcTemplatefrom an existing java.sql.Connection?
Technically, you can, using
SingleConnectionDataSourcenew JdbcTemplate(new SingleConnectionDataSource(connection, false))However, this is not quite advisable, unless for unit-tests for example.
You’d better use a full-featured
DataSourceand wire things using spring.