Spring JDBC Framework simplifies the use of JDBC and helps to avoid common errors.
The following example shows inserting a new record 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 = 6;
template.update("insert into USER values (?, ?, ?, ?)",
userId, "Steve", 66, 666666);
Map<String, Object> row = template.queryForMap(
"select * from USER where ID = ? ", userId);
System.out.println(row);
}