合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
### 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(); } } ~~~