try {
Class.forName("oracle.jdbc.driver.OracleDriver")
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:taian", "hr", "hr")//连接Oracle
conn.setAutoCommit(false)
Statement myStat = conn.createStatement()
String sqlTxt = "update BankAccount set account=account-" + this.amount.getText() + " where accId=" + this.payOut.getText()
System.out.println("第一步 执行:" + sqlTxt)
// 从汇出方扣减
try {
int affectedRow = myStat.executeUpdate(sqlTxt)
System.out.println("从汇出方扣减" + this.amount.getText() + "元,修改了" + affectedRow + "行数据.")
sqlTxt = "update BankAccount set account=account+" + this.amount.getText() + " where accId=" + this.saveIn.getText()
System.out.println("第二步 执行:" + sqlTxt)
affectedRow = myStat.executeUpdate(sqlTxt)
System.out.println("从汇入方增加" + this.amount.getText() + "元,修改了" + affectedRow + "行数据.")
// 事务成功结束, 提交
conn.commit()
} catch (SQLException sqlEx) {
System.out.println("耶!语句写错了吧")
sqlEx.printStackTrace()
// 事务中断,整体回滚到事务开始前状态
conn.rollback()
}
// 汇入方增加帐户余额
myStat.close()
conn.close()
} catch (Exception ex) {
System.out.println("反正是出错了.")
}
}//
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)