📄 atm8.java
字号:
Stmt.addBatch("insert into atm values("+h1+","+h2+","+n1+","+n2+","+n3+","+e1+",Null,Null)");
Stmt.executeBatch();
Con.commit();
h=new Chuhu(h1,h2,n1,n2,n3,e1);
t1.setText("");t2.setText(""); t3.setText("");
t4.setText("");myPassword4.setText("");t6.setText("");
A=f1.getText(); //注册功能中数据库的连接
B=Integer.parseInt(myPassword.getText());
ResultSet rs=Stmt.executeQuery("SELECT * FROM atm where zhanghao="+A+" AND mima="+B+"");
while(rs.next())
{ String name1=rs.getString("name");String sex1=rs.getString("sex");int bodyNo1=rs.getInt("shenfen");int z_hao1=rs.getInt("zhanghao");int mima1=rs.getInt("mima");
int money1=rs.getInt("money");}
}catch (ClassNotFoundException e5) {
e5.printStackTrace();
} catch(SQLException e1) { System.out.println(e1.toString());
JOptionPane.showMessageDialog(null,"连接数据库失败,请稍后再连接","Error", JOptionPane.ERROR_MESSAGE); }
}
//JOptionPane.showMessageDialog(null,"注册成功,欢迎使用中国公商银行取款机!","消息对话框",JOptionPane.INFORMATION_MESSAGE);
if(e.getActionCommand()=="返回")
{ t1.setText("");t2.setText(""); t3.setText("");
t4.setText("");myPassword4.setText("");t6.setText("");cq.show(c,"one");}
if(e.getActionCommand()=="登陆")
{ try
{
Class.forName("com.mysql.jdbc.Driver");
Con=DriverManager.getConnection("jdbc:mysql://localhost/mydate?user=root&password=831027");
Statement Stm =Con.createStatement();
Con.setAutoCommit(false);
A=f1.getText(); //注册功能中数据库的连接
B=Integer.parseInt(myPassword.getText());
ResultSet rt=Stm.executeQuery("SELECT * FROM atm where zhanghao="+f()+" AND mima="+B+"");
while(rt.next())
{
int zhanghao=rt.getInt("zhanghao");int mima=rt.getInt("mima");
//if(h.z_hao!=Integer.parseInt(f1.getText())||h.mima!=Integer.parseInt(myPassword.getText()))
if((Integer.parseInt(f1.getText())!=Integer.parseInt(rt.getString("zhanghao")))||Integer.parseInt(myPassword.getText())!=rt.getInt("mima"))
{JOptionPane.showMessageDialog(null,"您的帐号或密码错误:请重新输入","消息对话框",JOptionPane.INFORMATION_MESSAGE);
f1.setText("");myPassword.setText("");}
else
if (myPassword.getText().length() < 6)
{
JOptionPane.showMessageDialog(null, "对不起,密码为6位数,请重新输入!", "Error", JOptionPane.ERROR_MESSAGE);
myPassword.setText("");}
else
{cq.show(c,"3");myPassword.setText("");} }}catch(ClassNotFoundException e5) {
e5.printStackTrace();
} catch(SQLException e1) { System.out.println(e1.toString());}
}
if(e.getActionCommand()=="取款")
{ cq.show(c,"4"); }
if(e.getActionCommand()=="退回")
{ cq.show(c,"3"); }
if(e.getActionCommand()=="输入")
{
int i=Integer.parseInt(f3.getText());
ResultSet rm=h.DispDate(f());
Connection con=h.getconn();
PreparedStatement pr=null;
try{
while(rm.next())
{int m=rm.getInt("money");
if(i>0&&i<=5000)
{int n=m-i;
String t="update atm set qukuan="+i+",money="+n+" where zhanghao="+f()+" ";
pr=con.prepareStatement(t);
pr.executeUpdate(t);
JOptionPane.showMessageDialog(null,"系统正在运行,请等待","消息对话框",JOptionPane.INFORMATION_MESSAGE);
cq.show(c,"3");
}} }catch(SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// else
// if(i>10000)
//{JOptionPane.showMessageDialog(null,"您只能够取50或100两种人民币且不能超过10000;","消息对话框",JOptionPane.INFORMATION_MESSAGE);cq.show(c,"3");}
//else
// {JOptionPane.showMessageDialog(null,"您的余额不足,不能取款","消息对话框",JOptionPane.INFORMATION_MESSAGE);cq.show(c,"3");}
f3.setText("");}
if(e.getActionCommand()=="继续服务")
{cq.show(c,"one");}
if(e.getActionCommand()=="余额查询")
{cq.show(c,"5");//int k1,k2;
ResultSet rm=h.DispDate(f());
try{
while(rm.next())
{
l9.setText("您的余额为:"+rm.getInt("money"));}
}catch(SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(e.getActionCommand()=="确定")
{cq.show(c,"3");}
if(e.getActionCommand()=="储户查询")
{ cq.show(c,"8"); }
if(e.getActionCommand()=="确定")
{ cq.show(c,"3");
ResultSet rm=h.DispDate(f());
try{
while(rm.next())
{String s="帐号:"+rm.getInt("zhanghao")+"\n"+"密码:"+"******"+"\n"+"姓名:"+rm.getString("name")+"\n"+"性别:"+rm.getString("sex")+"\n"+"金额:"+rm.getInt("money");
D1.setText("储户查询"+"\n"+s);}
}catch(SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(e.getActionCommand()=="修改密码")
{cq.show(c,"6");}
if(e.getSource()==b9)
{
int p,t,i;
p=Integer.parseInt(f6.getText());
t=Integer.parseInt( myPassword2.getText());
i=Integer.parseInt( myPassword3.getText());
ResultSet rm=h.DispDate(f());
Connection con=h.getconn();
PreparedStatement pr=null;
try{
while(rm.next())
{if(p==rm.getInt("mima"))
{if (myPassword2.getText().length()!=6&&myPassword3.getText().length()!=6) //密码修改的条件
{
JOptionPane.showMessageDialog(null, "对不起,密码应为6位数,请重新输入!", "Error", JOptionPane.ERROR_MESSAGE);
myPassword2.setText(""); myPassword3.setText("");}
if(t==i)
{JOptionPane.showMessageDialog(null,"密码修改成功","消息对话框",JOptionPane.INFORMATION_MESSAGE);
myPassword2.setText(""); myPassword3.setText("");f6.setText("");cq.show(c,"3");}
// else
//{JOptionPane.showMessageDialog(null,"您输入的新密码不一致,请从新输入","消息对话框",
// JOptionPane.INFORMATION_MESSAGE); myPassword2.setText(""); myPassword3.setText("");cq.show(c,"3");}
else
{ JOptionPane.showMessageDialog(null,"你的原密码不正确,请从新输入","消息对话框",JOptionPane.INFORMATION_MESSAGE);
f6.setText("");cq.show(c,"3"); }
String mi="update atm set mima="+t+" where zhanghao="+f()+"";
pr=con.prepareStatement(mi);
pr.executeUpdate(mi);}}
//int mon=rm.getInt("money")-i;}
} catch(SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(e.getActionCommand()=="返回")
{ cq.show(c,"one"); }
if(e.getActionCommand()=="转帐")
{cq.show(c,"7"); }
if(e.getSource()==b11)
{ int p;
p=Integer.parseInt(f7.getText());
ResultSet rm=h.DispDate(f());
Connection con=h.getconn();
PreparedStatement pr=null;
//PreparedStatement xx=null;
try{
while(rm.next())
{int m=rm.getInt("money");
int n=m-p;
if(n>10)
{
String t="update atm set zhuangz="+p+",money="+n+" where zhanghao="+f()+" ";
pr=con.prepareStatement(t);
pr.executeUpdate(t);
//int a=select money from atm where zhanghao=f8.getText();
//String x="update atm set money=("+n+"+(select money from atm where zhanghao=f8.getText();)) where zhanghao="+f8.getText()+" ";
//xx=con.prepareStatement(x);
// xx.executeUpdate(x);
JOptionPane.showMessageDialog(null,"转帐成功","消息对话框",JOptionPane.INFORMATION_MESSAGE);
f7.setText("");h.money=h.money-p; cq.show(c,"3");//int mon=rm.getInt("money")-i;}
}else
{JOptionPane.showMessageDialog(null,"余额不足,不能转帐","消息对话框",JOptionPane.INFORMATION_MESSAGE);
f7.setText("");cq.show(c,"3");}} }catch(SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
class Quit implements WindowListener
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowOpened(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
}
public class ATM8 //定义主类
{
public static void main(String args[])
{Chuhu c=new Chuhu();
Uframe m=new Uframe();m.show();
c.DispDate(m.f());
m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class Chuhu extends Manager // 储户类的定义
{ //Uframe n=new Uframe();
int money;StringBuffer s=new StringBuffer();String t="";Connection conn=null;
Chuhu(String name1,String sex1,int bodyNo1,int z_hao1,int mima1,int money1)
{
name=name1;sex=sex1;
bodyNo=bodyNo1;
z_hao=z_hao1;
mima=mima1;
money=money1; }
Chuhu()
{ No++; }
public Connection getconn(){
try {
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost/mydate?user=root&password=831027");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch(SQLException e1){
e1.printStackTrace();
}
return conn;
}
public ResultSet DispDate(int a){
String s="";
Connection conn=this.getconn();
PreparedStatement pr=null;
ResultSet re=null;
try{
String sql="SELECT * FROM atm where zhanghao="+a+"";
pr=conn.prepareStatement(sql);
re=pr.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return re;
}
}
class Manager //定义构造函数
{
int No;
String name;
String sex;
int bodyNo;
int z_hao;
int mima;Chuhu use[]=new Chuhu[9];
Manager()
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -