您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 薪酬管理 > Java-银行管理系统源代码
Java小型银行管理系统源代码(图形界面)accounts.javapackageAccount;publicclassaccounts{protectedintid;//银行账号protectedStringpassword;//用户密码protectedStringname;//用户型号protectedStringpersonId;//身份账号protectedintaccountType;//账号类型,0代表储蓄卡,1代表信用卡protecteddoublebalance;//账户余额。之所以定义为protected是让他的子类可以直接用,不需要通过方法来赋值。protecteddoubleceiling;publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringpassword){this.password=password;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicStringgetPersonId(){returnpersonId;}publicvoidsetPersonId(StringpersonId){this.personId=personId;}publicintgetAccountType(){returnaccountType;}publicvoidsetAccountType(intaccountType){this.accountType=accountType;}publicdoublegetBalance(){returnbalance;}publicvoidsetBalance(doublebalance){this.balance=balance;}publicintgetId(){returnid;}publicvoidsetId(intid){this.id=id;}publicdoublegetCeiling(){returnceiling;}publicvoidsetCeiling(doubleceiling){this.ceiling=ceiling;}//无参数构造方法publicaccounts(){}//构造方法publicaccounts(Stringpassword,Stringname,StringpersonId,intaccountType,doublebalance,doubleceiling){super();this.password=password;this.name=name;this.personId=personId;this.accountType=accountType;this.balance=balance;this.ceiling=ceiling;}//存款publicvoiddeposit(doublemoney){balance+=money;}//取款publicvoidwithdraw(doublemoney){if(accountType==1){if((balance+ceiling)money){System.out.println(对不起,已超出您的信用额度!);}else{balance-=money;}}else{if(balancemoney){System.out.println(对不起,账户余额不足!);}else{balance-=money;}}}}DBoper.javapackageDB;importjava.sql.*;importjava.util.ArrayList;importAccount.accounts;publicclassDBoper{privateConnectionconn=null;privateStatementst=null;privatePreparedStatementpstmt=null;privateResultSetrs=null;privateArrayListaccountsresult;//连接数据库publicConnectiongetConnection(){try{Class.forName(com.mysql.jdbc.Driver);conn=DriverManager.getConnection(jdbc:mysql://localhost:3306/bankmanager?useUnicode=true&characterEncoding=utf8,root,xuewei);}catch(Exceptione){System.out.println(数据库连接失败);}returnconn;}//修改删除用户数据publicbooleanaccountDataUpdate(Stringsql){conn=getConnection();try{pstmt=conn.prepareStatement(sql);pstmt.executeUpdate();//System.out.println(数据更新成功);conn.close();returntrue;}catch(SQLExceptione){e.printStackTrace();//System.out.println(更新失败);returnfalse;}}//依据id来修改记录publicbooleandataupdateid(accountsuser,intid){conn=getConnection();try{Stringsql=updateaccountsetusername=?,userpwd=?,personId=?,accountType=?,balance=?,ceiling=?whereid=+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();System.out.println(操作成功);returntrue;}catch(SQLExceptione){e.printStackTrace();System.out.println(操作失败);returnfalse;}}//插入用户数据publicbooleanaccountDataInsert(accountsaccount){conn=getConnection();try{pstmt=conn.prepareStatement(insertintoaccount(username,userpwd,personId,accountType,balance,ceiling)values(?,?,?,?,?,?));pstmt.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();System.out.println(新用户数据插入成功);conn.close();returntrue;}catch(SQLExceptione){e.printStackTrace();System.out.println(插入失败);returnfalse;}}//查询数据publicResultSetdataquery(Stringsql){conn=getConnection();try{pstmt=conn.prepareStatement(sql);rs=pstmt.executeQuery();}catch(SQLExceptione){e.printStackTrace();System.out.println(检索失败);}returnrs;}publicResultSettestlist(){try{Stringsql=select*fromaccountwhereid=1001;pstmt=conn.prepareStatement(sql);System.out.println(sql);rs=pstmt.executeQuery();}catch(SQLExceptione){e.printStackTrace();System.out.println(检索失败);}returnrs;}publicArrayListaccountstestt(intid){ArrayListaccountslist=newArrayListaccounts();conn=getConnection();try{Stringsql=select*fromaccountwhereid=+id;pstmt=conn.prepareStatement(sql);rs=pstmt.executeQuery();while(rs.next()){accountsuser=newaccounts();user.setName(rs.getString(username));user.setPassword(rs.getString(userpwd));user.setPersonId(rs.getString(personId));user.setAccountType(rs.getInt(accountType));user.setBalance(rs.getDouble(balance));user.setCeiling(rs.getDouble(ceiling));list.add(user);}}catch(SQLExceptione){e.printStackTrace();System.out.println(检索失败);}returnlist;}//根据卡号和密码验证用户是否存在publicbooleanverify(intid,Stringpassword){conn=getConnection();try{pstmt=conn.prepareStatement(select*fromaccountwhereid=?anduserpwd=?);pstmt.setInt(1,id);pstmt.setString(2,password);rs=pstmt.executeQuery();if(rs.next()){returntrue;}else{returnfalse;}}catch(SQLExceptione){e.printStackTrace();returnfalse;}}/***登录验证*/publicaccountsverifyAccount(intid,Stringpassword){booleanflag=verify(id,password);if(flag){accountsaccount=queryByIDandPassword(id,password);returnaccount;}else{System
本文标题:Java-银行管理系统源代码
链接地址:https://www.777doc.com/doc-2236147 .html