1、Java银行管理系统源代码Java小型银行管理系统源代码(图形界面)accounts.javapackage Account;public class accounts protected int id;/银行账号 protected String password;/用户密码 protected String name;/用户型号 protected String personId;/身份账号 protected int accountType;/账号类型,0代表储蓄卡,1代表信用卡 protected double balance;/账户余额。之所以定义为protected是让他的子类可以
2、直接用,不需要通过方法来赋值。 protected double ceiling; public String getPassword() return password; public void setPassword(String password) this.password=password; public String getName() return name; public void setName(String name) this.name=name; public String getPersonId() return personId; public void setPe
3、rsonId(String personId) this.personId=personId; public int getAccountType() return accountType; public void setAccountType(int accountType) this.accountType=accountType; public double getBalance() return balance; public void setBalance(double balance) this.balance=balance; public int getId() return
4、id; public void setId(int id) this.id=id; public double getCeiling() return ceiling; public void setCeiling(double ceiling) this.ceiling=ceiling; /无参数构造方法 public accounts() /构造方法 public accounts(String password,String name,String personId,int accountType, double balance,double ceiling) super(); this
5、.password=password; this.name=name; this.personId=personId; this.accountType=accountType; this.balance=balance; this.ceiling=ceiling; /存款 public void deposit(double money) balance+=money; /取款 public void withdraw(double money) if(accountType=1) if(balance+ceiling)money) 对不起,已超出您的信用额度!); else balance
6、-=money; else if(balancemoney) 对不起,账户余额不足!); else balance-=money; DBoper.javapackage DB;import java.sql.*;import ;import Account.accounts;public class DBoper private Connection conn = null; private Statement st = null; private PreparedStatement pstmt = null; private ResultSet rs = null; private Arra
7、yList result; /连接数据库 public Connection getConnection() try Class.forName(); conn=DriverManager.getConnection(jdbc:,root,xuewei); catch(Exception e) 数据库连接失败); return conn; /修改 删除用户数据 public boolean accountDataUpdate(String sql) conn=getConnection(); try pstmt=conn.prepareStatement(sql); pstmt.execute
8、Update(); /数据更新成功); conn.close(); return true; catch(SQLException e) e.printStackTrace(); /更新失败); return false; /依据id来修改记录 public boolean dataupdateid(accounts user, int id) conn = getConnection(); try String sql = update account set username=?,userpwd=?,personId=?,accountType=?,balance=?,ceiling=?
9、where id= + id; pstmt = conn.prepareStatement(sql); pstmt.setString(1, user.getName(); pstmt.setString(2, user.getPassword(); pstmt.setString(3, user.getPersonId(); pstmt.setInt(4, user.getAccountType(); pstmt.setDouble(5, user.getBalance(); pstmt.setDouble(6, user.getCeiling(); pstmt.executeUpdate(
10、); 操作成功); return true; catch (SQLException e) e.printStackTrace(); 操作失败); return false; /插入用户数据 public boolean accountDataInsert(accounts account) conn=getConnection(); try pstmt=conn.prepareStatement(insert into account (username,userpwd,personId,accountType,balance,ceiling) values (?,?,?,?,?,?); p
11、stmt.setString(1, account.getName(); pstmt.setString(2, account.getPassword(); pstmt.setString(3, account.getPersonId(); pstmt.setInt(4, account.getAccountType(); pstmt.setDouble(5, account.getBalance(); pstmt.setDouble(6, account.getCeiling(); pstmt.executeUpdate(); 新用户数据插入成功); conn.close(); return
12、 true; catch(SQLException e) e.printStackTrace(); 插入失败); return false; /查询数据 public ResultSet dataquery(String sql) conn = getConnection(); try pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); catch (SQLException e) e.printStackTrace(); 检索失败); return rs; public ResultSet testlist() try
13、 String sql = select * from account where id =1001; pstmt = conn.prepareStatement(sql); ; rs = pstmt.executeQuery(); catch (SQLException e) e.printStackTrace(); 检索失败); return rs; public ArrayList testt(int id) ArrayList list = new ArrayList(); conn = getConnection(); try String sql = select * from a
14、ccount where id= + id; pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); while (rs.next() accounts user = new accounts(); user.setName(rs.getString(username); user.setPassword(rs.getString(userpwd); user.setPersonId(rs.getString(personId); user.setAccountType(rs.getInt(accountType); use
15、r.setBalance(rs.getDouble(balance); user.setCeiling(rs.getDouble(ceiling); list.add(user); catch (SQLException e) e.printStackTrace(); 检索失败); return list; /根据卡号和密码验证用户是否存在 public boolean verify(int id,String password) conn=getConnection(); try pstmt=conn.prepareStatement(select * from account where
16、id=? and userpwd=?); pstmt.setInt(1, id); pstmt.setString(2, password); rs=pstmt.executeQuery(); if(rs.next() return true; else return false; catch(SQLException e) e.printStackTrace(); return false; /* * 登录验证 */ public accounts verifyAccount(int id, String password) boolean flag = verify(id, passwor
17、d); if(flag) accounts account=queryByIDandPassword(id, password); return account; else 用户不存在!); return null; /根据卡号和密码查询信息 public accounts queryByIDandPassword(int id,String password) conn=getConnection(); try pstmt=conn.prepareStatement(select * from account where id=? and userpwd=?); pstmt.setInt(1
18、, id); pstmt.setString(2, password); rs=pstmt.executeQuery(); accounts account=new accounts(); while(rs.next() account.setId(rs.getInt(id); account.setName(rs.getString(username); account.setPassword(rs.getString(userpwd); account.setPersonId(rs.getString(personId); account.setAccountType(rs.getInt(
19、accountType); account.setBalance(rs.getDouble(balance); account.setCeiling(rs.getDouble(ceiling); return account; catch(SQLException e) e.printStackTrace(); return null; /根据卡号查询信息 public accounts queryByID(int id) conn=getConnection(); try pstmt=conn.prepareStatement(select * from account where id=?
20、); pstmt.setInt(1, id); rs=pstmt.executeQuery(); accounts account=new accounts(); while(rs.next() account.setId(rs.getInt(id); account.setName(rs.getString(username); account.setPassword(rs.getString(userpwd); account.setPersonId(rs.getString(personId); account.setAccountType(rs.getInt(accountType);
21、 account.setBalance(rs.getDouble(balance); account.setCeiling(rs.getDouble(ceiling); return account; catch(SQLException e) e.printStackTrace(); return null; public static void main(String args) / TODO Auto-generated method stub DBoper op=new DBoper(); ArrayList list=op.testt(1001); for(int i=0;ilist
22、.size();i+) accounts user=new accounts(); user=list.get(i); ; ; ; ; ; ; /图像界面文件夹DN_SYSTEMDefault.java /主界面package DN_SYSTEM;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import Account.accounts;import DB.DBoper;public class Default extends JFrame implements ActionLi
23、stener accounts account=DN_ATM.client; DBoper db=new DBoper(); private JFrame jf; private JButton btn0,btn1,btn2,btn3,btn4,btn5; private Container c; public void defaltDemo() /添加主界面卡片 /DN_ATM.id; int id=DN_ATM.id; /account=db.queryByID(id); jf=new JFrame(DEFAULT); c=jf.getContentPane(); c.setLayout(
24、null); c.setBackground(new Color(119,119,253); JLabel lblwel = new JLabel(欢迎+account.getName()+用达能银行ATM系统); lblwel.setBounds(20, 15, 350, 30); c.add(lblwel); JLabel lblwel1 = new JLabel(请选择您需要的交易类型); lblwel1.setBounds(120, 45, 350, 30); c.add(lblwel1); btn1 = new JButton(取款服务); btn1.addActionListene
25、r(this); btn1.setBounds(70, 90, 100, 30); c.add(btn1); btn2=new JButton(存款服务); btn2.addActionListener(this); btn2.setBounds(210, 90, 100, 30); c.add(btn2); btn3 = new JButton(查询余额); btn3.addActionListener(this); btn3.setBounds(70, 150, 100, 30); c.add(btn3); btn4 = new JButton(转账服务); btn4.addActionL
26、istener(this); btn4.setBounds(210, 150, 100, 30); c.add(btn4); btn5 = new JButton(注销账户); btn5.addActionListener(this); btn5.setBounds(70, 210, 100, 30); c.add(btn5); btn0 = new JButton(退出操作); btn0.addActionListener(this); btn0.setBounds(210, 210, 100, 30); c.add(btn0); jf.setVisible(true); jf.setRes
27、izable(false); jf.setSize(400,300); jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); /事件处理 Override public void actionPerformed(ActionEvent e) /取款服务 if(e.getSource().equals(btn1) OutMoney outmoney=new OutMoney(); outmoney.outMoney(); jf.dispose(); /存款服务 if(e.getSource().equals(btn2) InMoney inmoney=new InMoney(); inmoney.InMoney(); jf.dispose(); /查询余额 if
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1