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;
推荐阅读
- 包含postgresql修改字段长度的词条
- linux下redis环境变量,linux配置redis环境变量
- 如何修改pdf页数,pdf怎么修改页数
- 著名主播直播卖货话术,直播卖货台词大全集
- c语言常用定位函数 c语言常用定位函数有哪些
- 池州专业sap软件服务,池州哪里有那个服务
- phpcms怎么恢复数据库,phpcms数据库文件
- 手机申请西瓜视频直播,申请西瓜视频直播条件
- java关闭窗体代码6的简单介绍