企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
### 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(); } } ~~~