java程序设计银行代码 java设计一个bank类实现银行( 二 )


ClientMessage student=new ClientMessage();
student.setMoney(rs.getFloat("money"));
student.setType(rs.getString("type"));
student.setClientName(rs.getString("ClientName"));
student.setTransactionID(rs.getInt("TransactionID"));
return student;
}
public Client login(Connection con,String ClientName,String password) throws Exception{
String sql="select balance,password,ClientName from Client where ClientName=? and password=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, ClientName);
ps.setString(2, password);
ResultSet rs=ps.executeQuery();
t=password;
b=ClientName;
System.out.println(t);
System.out.println(b);
if(rs.next()){
Client client=new Client();
client.setClientName(rs.getString("ClientName"));
client.setPassword(rs.getString("password"));
return client;}
throw new Exception("Can not login, the accountID or password has error. ");
} public void save(Connection con ,String money)throws Exception
{// a++;
String s="save";
float g=Float.parseFloat(money);
String sql="update Client set balance=balance+? where ClientName=?";
String sql1="insert into ATMTransaction(ClientName,Type,money)values(?,?,?) ";
PreparedStatement ps=con.prepareStatement(sql);
PreparedStatement ps1=con.prepareStatement(sql1);
ps.setFloat(1, g);
ps.setString(2,b);
//ps1.setInt(1,a);
ps1.setString(1,b);
ps1.setString(2,s);
ps1.setFloat(3,g);
ps.executeUpdate();
ps1.executeUpdate();
}
public void withDraw (Connection con ,String money)throws Exception
{//a++;
String s="WithDraw";
float x=Float.parseFloat(money);
String sql="update Client set balance=balance-? where ClientName=?";
String sql1="insert into ATMTransaction(ClientName,Type,money) values(?,?,?)";
PreparedStatement ps=con.prepareStatement(sql);
PreparedStatement ps1=con.prepareStatement(sql1);
ps.setFloat(1, x);
ps.setString(2,b);
//ps1.setInt(1,a);
ps1.setString(1,b);
ps1.setString(2,s);
ps1.setFloat(3,x);
ps.executeUpdate();
ps1.executeUpdate();
}
public String changePassword(Connection con, String OldPassWord,String newPassWord1,String newPassWord2)
throws Exception
{
if(t.equals(OldPassWord))
{
if(newPassWord1.equals(newPassWord2))
{
String sql="update Client set password=? where ClientName=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, newPassWord1);
ps.setString(2,b);
ps.executeUpdate();
String j="dsfasdf";
return j;
}
else
{System.out.print("确认密码错误java程序设计银行代码!");brreturn null;}
}
else
{return null;
}
}
public ArrayListClientMessage disPlayAll(Connection con ) throws Exception
{
String sql="select * from ATMTransaction where ClientName=? ";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,b);
System.out.println(b+"****b****");
ResultSet rs=ps.executeQuery();
ArrayListClientMessage message=new ArrayListClientMessage();
while(rs.next()){
message.add(this.getClientMessage(rs));
}
return message;
}
public float showBalance(Connection con ) throws Exception
{
String sql="select balance from Client where ClientName=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, b);
ResultSet rs=ps.executeQuery();
if(rs.next())
{
float s;
s=rs.getFloat("balance");
return s;
}
else return 0 ;
}
}
用JAVA编程设计一个银行账户类,其中包括以下内容 , 并用字符界面模拟存款和取款过程 。import java.util.Scanner;

推荐阅读