• jdbc实现事务


    //conn需要自己获取,这里我用的时springjdbcTemplate
    Connection conn = null; PreparedStatement pstm = null; try { conn = jdbc.getDataSource().getConnection(); } catch (SQLException e1) { log.error(e1.getMessage()); return "服务器错误!"; } FatherModule firstErrorFatherModule = null; String sql = null; try { for(FatherModule fatherModule : fatherModules) { firstErrorFatherModule = fatherModule; sql = "update sfk_father_module t set t.sort = ? where t.id = ?;"; pstm = conn.prepareStatement(sql); pstm.setInt(1, fatherModule.getSort());//注意从1开始 pstm.setLong(2, fatherModule.getId()); pstm.executeUpdate();//注意这里为空 } conn.commit(); } catch (SQLException e) { log.error(e.getMessage()); try { conn.rollback(); } catch (SQLException e1) { log.error("后台错误"); } return "sortId = "+firstErrorFatherModule.getSort(); } finally { if(pstm!=null) { try { pstm.close(); } catch (SQLException e) { log.error(e.getMessage()); } } if(conn!=null) { try { conn.close(); } catch (SQLException e) { log.error(e.getMessage()); } } } return null;
  • 相关阅读:
    数据攻略●R语言自述
    测试实例
    xml反射
    过滤器
    使用s标签来进行简单的表格配置
    将Spring、Hibernate、Struts2连接起来
    Spring容器
    初见Spring框架
    Spring框架的AOP
    Hibernate里面的几个方法
  • 原文地址:https://www.cnblogs.com/rocky-AGE-24/p/5929555.html
Copyright © 2020-2023  润新知