Spring JDBC Framework simplifies the use of JDBC and helps to avoid common errors.
The following example shows updating an existing 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);
String statusToCheck = "RESOLVED";
Map<String, Object> row = template.queryForMap(
"select * from BUG_STAT where STATUS = ? ", statusToCheck);
System.out.println(row);
//Update the row int countToUpdate = 18;
template.update("update BUG_STAT set COUNT = ? where STATUS = ?",
countToUpdate, statusToCheck);
row = template.queryForMap(
"select * from BUG_STAT where STATUS = ? ", statusToCheck);
System.out.println(row);
}