📄 transfermoney.java
字号:
/** * JDBC Stored Procedure ITSO.transferMoney * @param account1 * @param account2 * @param amount * @param success *//**
* Header fragment inserted from SP_JAVA_HDR.FRAGMENT
*/import java.sql.*; // JDBC classespublic class TransferMoney{ public static void transferMoney ( String account1, String account2, java.math.BigDecimal amount, int[] success ) throws SQLException, Exception { // Get connection to the database Connection con = DriverManager.getConnection("jdbc:default:connection"); PreparedStatement stmt = null; PreparedStatement stmt2 = null; int updateCount = 0; int updateCount2 = 0; String sql, sql2; sql = "UPDATE ITSO.ACCOUNT" + " SET BALANCE = (BALANCE - ?) " + " WHERE ACCID = ? " + " AND BALANCE > ?"; stmt = con.prepareStatement( sql ); stmt.setBigDecimal( 1, amount ); stmt.setString( 2, account1 ); stmt.setBigDecimal( 3, amount ); updateCount = stmt.executeUpdate(); sql2 = "UPDATE ITSO.ACCOUNT" + " SET BALANCE = (BALANCE + ?) " + " WHERE ACCID = ?"; stmt2 = con.prepareStatement( sql2 ); stmt2.setBigDecimal( 1, amount ); stmt2.setString( 2, account2 ); updateCount2 = stmt2.executeUpdate(); // Set return parameter success[0] = updateCount + updateCount2; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -