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

📄 customersindb.java

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

import java.sql.*;

public class CustomersInDB implements Customers {
	private Connection conn;

	public CustomersInDB(Connection conn) {
		this.conn = conn;
	}
	public Customer loadCustomer(String customerId) {
		try {
			PreparedStatement st = conn.prepareStatement("select * from customers where id=?");
			try {
				st.setString(1, customerId);
				ResultSet rs = st.executeQuery();
				if (!rs.next()) {
					throw new RuntimeException("Customer has been deleted");
				}
				return new Customer(
						customerId,
						rs.getString("name"),
						rs.getString("address"));
			} finally {
				st.close();
			}
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
	public void saveCustomer(Customer customer) {
		try {
			PreparedStatement st = 
				conn.prepareStatement("update customers set name=?, address=? where id=?");
			try {
				st.setString(1, customer.getName());
				st.setString(2, customer.getAddress());
				st.setString(3, customer.getId());
				st.executeUpdate();
			} finally {
				st.close();
			}
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

}

⌨️ 快捷键说明

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