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

📄 accountimpl.java

📁 基于corba的资源池,实现了实例池供客户端调用,并且实例池对实例的分配采用策略模式支持随即抽取,最近使用和循环抽取三个不同策略.(在visibroke下面开发的)
💻 JAVA
字号:
//Account的实现类
package interfaceImpl;

import java.sql.SQLException;
import database.DatabaseAccess;
import java.sql.ResultSet;

public class AccountImpl extends Bank.AccountPOA
{
    // 属性定义
	protected String name;
	protected float balance;
	private String id;
	private static String DatabaseSource ="jdbc:odbc:BankingDataSource";
	private static DatabaseAccess dbAccess = new DatabaseAccess(DatabaseSource);;
	
	//构造方法
	public  AccountImpl(String id,String name, float balance)
	{
		this.id = id;
		this.name = name;
		this.balance = balance;
	}
	
	public AccountImpl()
	{
		this(null,null,0);
	}
	
    // 往账户中存款
    public void deposit(float amount) 
    {
    	balance += amount;
    	updataAccount(balance);
    }
    // 从账户中取款,不足余额则返回false
    public boolean withdraw(float amount)
    {
        if (balance < amount)  return false;
        else {
            balance -= amount;
            updataAccount(balance);
            return true;
        }
    }
    
	//更新数据库的数据
	public void updataAccount(float balance)
	{
		String sql = "UPDATE  Accounts SET balance = "+ 
						balance + " WHERE id = '" + this.id + "'";
		try{
			dbAccess.update(sql);
		}catch(SQLException e){
			e.printStackTrace();
		}	
	}
    
    public String getId(){return id;}
    
	public String getName(){return name;}
	
	public float getBalance()
	{
		String sql = "SELECT  balance FROM Accounts WHERE id = '" + this.id + "'";
		try{
			ResultSet rs = dbAccess.query(sql);
			while (rs.next())
				balance = rs.getFloat(1);
			rs.close();
		}catch (SQLException e){
			e.printStackTrace();
			System.out.println("SQL出错");
		}catch (Exception e){
			e.printStackTrace();
		}
		return balance;
	}
	
	public void setName(String name){this.name = name;}
	
	public void setId(String id){this.id = id;}
	
	public void setBalance(float bal){this.balance = bal;}

}

⌨️ 快捷键说明

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