NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
### DBUtils完成转账 ~~~ Connection connection = null; try { QueryRunner queryRunner = new QueryRunner(); //得使用这种构造函数,因为传入连接池的我们不能保证执行SQL语句的是同一个连接.  connection = C3P0Utils.getConnection(); connection.setAutoCommit(false); int tom = queryRunner.update(connection, "update account set money = money - ? where name = ?", 1000, "tom"); int jack = queryRunner.update(connection, "update account set money = money + ? where name = ?", 1000, "jack"); System.out.println(1 / 0); connection.commit(); if (tom > 0 && jack > 0) { System.out.println("转账成功"); } } catch (SQLException e) { try { connection.rollback(); } catch (SQLException sql) { sql.printStackTrace(); } e.printStackTrace(); } finally { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } ~~~