Spring MVC : Database Connectivity

Another way to access database without using applicationContext.xml is as follows :

DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
dataSource.setUrl("jdbc:oracle:thin:@localhost:1521:XE");
dataSource.setUsername("username");
dataSource.setPassword("pwd");
JdbcTemplate jt = new JdbcTemplate(dataSource);

Just place it in your controller and you're done. ;)

0 comments: