datasource bean creation for JdbcTemplate

Hi All,

I want to use Jdbc Template in my module.for this i need datasource bean to pass inside JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource); since in OpenMRS connection has established using DriverManager in the DatabaseUpdater.java. please guide me how i can create datasource bean in my module.

Here’s how you can do it http://stackoverflow.com/a/2449161 Basically use SingleConnectionDataSource with connection from SessionFactory.

can i establish connection with database twice. as i explained in my earlier post OpenMRS creating the conncetion in the DatabaseUpdater.java using DriverManager. i want to create dataSource bean but OpenMRS already established the connection using DriverManager.

SessionFactory uses a pool of DB connections. You can establish your own connection if needed as well.

I dont want to create SessionFactory from dataSource bean. I want to create DataSource bean to use JdbcTemplate.

Hi All,

I established the connection with same database using DriverManagerDataSource as below

@Bean public DriverManagerDataSource dataSource(){ Properties props = Context.getRuntimeProperties(); mergeDefaultRuntimePropertiess(props);

	String driver = props.getProperty("hibernate.connection.driver_class");
	String username = props.getProperty("hibernate.connection.username");
	String password = props.getProperty("hibernate.connection.password");
	String url = props.getProperty("hibernate.connection.url");
	
	DriverManagerDataSource dataSource = new DriverManagerDataSource();
	dataSource.setDriverClassName(driver);
	dataSource.setUsername(username);
	dataSource.setPassword(password);
	dataSource.setUrl(url);
    return dataSource;
}