我是 Spring 的新手..我正在尝试使用 jdbc 模板做一些数据库事务....程序运行良好但是当我在一些 DML
操作后从数据库中获取一些数据时,它没有显示更新的数据....在数据库中手动提交后显示刷新的数据....有没有办法使用 jdbc 模板从它自己的程序提交数据库....!!我正在使用 Spring 4.1.6 版本...请帮助...
public void create(Student s){
String sql = "insert into student(id,name,age)values(?,?,?)";
jdbcTemplate.update(sql,s.getId(),s.getName(),s.getAge());
System.out.println("Row Inserted");
//Logic for commit...???
return;
}
最佳答案
将@EnableTransactionManagement
注释添加到您的配置中并将该方法标记为@Transactional
。
因此在退出后提交方法事务(如果没有抛出异常)
参见 the example
关于java - 如何使用 jdbc 模板在 Spring 中提交事务 ..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44800648/