Spring JDBC Framework simplifies the use of JDBC and helps to avoid common errors.
The following example shows querying for a string using JdbcTemplate class.
/**
* Initialize context and get the JdbcTemplate
*/
ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
DataSource dataSource = (DataSource) appContext.getBean("dataSource");
JdbcTemplate template = new JdbcTemplate(dataSource);
int userId = 1;
String userName = template.queryForObject(
"select NAME from USER where ID = ?", String.class, userId);