zoukankan      html  css  js  c++  java
  • 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;
  • 相关阅读:
    android git问题File not found: git.exe
    asp.net 连接数据库的问题总结
    asp.net记账本
    asp.net对数据库增删改操作
    asp.net 连接数据库操作
    第九、十周周记
    作业四-兴趣问题清单
    价值观作业
    第七周周记
    第三次作业问卷调查
  • 原文地址:https://www.cnblogs.com/rocky-AGE-24/p/5929555.html
Copyright © 2011-2022 走看看