⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transfer.java

📁 Enjoy Web Dev With Tapestry 一书的源代码
💻 JAVA
字号:
package com.ttdev.bank;

import java.sql.*;

import javax.naming.*;
import javax.sql.*;

import org.apache.tapestry.html.*;

public abstract class Transfer extends BasePage {
	public abstract String getFromAccNo();

	public abstract String getToAccNo();

	public abstract int getAmount();

	public void onOk() {
		try {
			Context context = new InitialContext();
			DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/bankDataSource");
			Connection conn = ds.getConnection();
			try {
				conn.setAutoCommit(false);
				PreparedStatement st = conn
						.prepareStatement("update accounts set balance=balance-? where accno=?");
				try {
					st.setInt(1, getAmount());
					st.setString(2, getFromAccNo());
					st.executeUpdate();
				} finally {
					st.close();
				}
				st = conn
						.prepareStatement("update accounts set balance=balance+? where accno=?");
				try {
					st.setInt(1, getAmount());
					st.setString(2, getToAccNo());
					st.executeUpdate();
				} finally {
					st.close();
				}
				conn.commit();
			} catch (Exception e) {
				conn.rollback();
				throw e;
			} finally {
				conn.close();
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -