小型银行管理系统的功能代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

小型银行管理系统的部分代码登陆packagedao;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.util.ArrayList;importjava.util.List;importjava.sql.*;publicclasslogin{privateStringsName;privateStringsPass;privateStringsState;//数据库连接设置protectedstaticStringdbClassName=com.mysql.jdbc.Driver;protectedstaticStringdbUrl=jdbc:mysql://localhost:3306/bank;protectedstaticStringdbUser=root;protectedstaticStringdbPwd=root;privatestaticConnectionconn=null;publicStringgetsName(){returnsName;}publicvoidsetsName(StringsName){this.sName=sName;}publicStringgetsPass(){returnsPass;}publicvoidsetsSPass(StringsPass){this.sPass=sPass;}publicStringgetsState(){returnsState;}publicvoidsetsState(StringsState){this.sState=sState;}/***创建数据库连接**/privatevoidNewConnect(){try{if(conn==null){Class.forName(dbClassName).newInstance();conn=DriverManager.getConnection(dbUrl,dbUser,dbPwd);}elsereturn;}catch(Exceptionee){ee.printStackTrace();}}publicListstuSearch(){Stringsql=select*frompersonwherename='+sName+'andpass='+sPass+'andstate='+sState+';//System.out.println(sql);Listlist=newArrayList();ResultSetrs=null;try{if(conn==null)NewConnect();//如果数据库连接为空,则创建rs=conn.createStatement().executeQuery(sql);}catch(SQLExceptione){e.printStackTrace();}try{//通过循环,将数据结果集中的内容取出while(rs.next()){loginep=newlogin();ep.setsName(ep.getsName());ep.setsSPass(ep.getsPass());ep.setsState(ep.getsState());//System.out.println(ep.getsName()+ep.getsPass()+ep.getsState());list.add(ep);}}catch(SQLExceptione){//TODO自动生成catch块e.printStackTrace();}returnlist;//查询结果,数组返回}}数据库packagedao;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.Statement;publicclassshujuku{publicshujuku(Stringsql){//接受一个SQL语句并执行try{Class.forName(com.mysql.jdbc.Driver);Stringurl=jdbc:mysql://localhost/Bank?useUnicode=true&characterEncoding=GBK;Connectioncon=DriverManager.getConnection(url,root,root);Statementstmt=con.createStatement();stmt.executeUpdate(sql);stmt.close();}catch(Exceptione){e.printStackTrace();}}}数据packagedao;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.Statement;publicclassshuju{publicstaticStringshuj(){//查询出账户的最大值并返回这个最大值供其他方法调用Strings=null;try{Class.forName(com.mysql.jdbc.Driver);Stringurl=jdbc:mysql://localhost/Bank?useUnicode=true&characterEncoding=GBK;Connectioncon=DriverManager.getConnection(url,root,root);Statementstmt=con.createStatement();ResultSetrs=stmt.executeQuery(selectmax(cid)ascidfrom`Bank`.`yonghuxinxi`);while(rs.next())s=rs.getString(cid);stmt.close();rs.close();}catch(Exceptione){e.printStackTrace();}returns;}}数据库连接packagedao;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.util.ArrayList;importjava.util.List;importjava.util.Vector;importjava.sql.*;publicclassEmployee{privateStringename;privateStringeid;privateStringeaddr;privateStringesalary;privateStringepassward;privateStringesex;privateStringetel;//数据库连接设置protectedstaticStringdbClassName=com.mysql.jdbc.Driver;protectedstaticStringdbUrl=jdbc:mysql://localhost:3306/bank;protectedstaticStringdbUser=root;protectedstaticStringdbPwd=root;privatestaticConnectionconn=null;publicStringgetename(){returnename;}publicvoidsetename(Stringename){this.ename=ename;}publicStringgeteid(){returneid;}publicvoidseteid(Stringeid){this.eid=eid;}publicStringgeteaddr(){returneaddr;}publicvoidseteaddr(Stringeaddr){this.eaddr=eaddr;}publicStringgetesalary(){returnesalary;}publicvoidsetesalary(Stringesalary){this.esalary=esalary;}publicStringgetepassward(){returnepassward;}publicvoidsetepassward(Stringepassward){this.epassward=epassward;}publicStringgetesex(){returnesex;}publicvoidsetesex(Stringesex){this.esex=esex;}publicStringgetetel(){returnetel;}publicvoidsetetel(Stringetel){this.etel=etel;}/***创建数据库连接**/privatevoidNewConnect(){try{if(conn==null){Class.forName(dbClassName).newInstance();conn=DriverManager.getConnection(dbUrl,dbUser,dbPwd);}elsereturn;}catch(Exceptionee){ee.printStackTrace();}}/***增加员工*@paramstu*/publicvoidAddEmployee(){//拼装插入员工信息的SQL语句Stringssql=insertintoemployee(name,id,addr,salary,passward,sex,tel)values(+'+this.ename+',+'+this.eid+',+'+this.eaddr+',+'+this.esalary+',+'+this.epassward+',+'+this.esex+',+'+this.etel+');System.out.println(ssql);try{if(conn==null)NewConnect();//如果数据库连接为空,则创建//执行SQL语句,插入员工信息conn.createStatement().executeUpdate(ssql);}catch(SQLExceptione){e.printStackTrace();}}/***删除员工*@paramstu*/publicvoidDelEmployee(){//拼装删除员工的SQL语句Stringssql=deletefromemployeewhereid='+this.eid+';try{if(conn==null)NewConnect();//如果数据库连接为空,则创建//执行SQL语句,删除员工信息conn.createStatement().executeUpdate(ssql);}catch(SQLExceptione){e.printStackTrace();}}/***员工查询*@paramx*@return*/publicVectorVectorstuSearch(){//拼装查询员工的SQL语句Stringsql=selectname,id,addr,salary,passward,sex,telfromemployee;//如果姓名非空,则将姓名作为查询条件if(this.ename!=null){sql+=wherename='+this.ename+';}//如果性别非空,则将性别作为查询条件VectorVectorv=newVectorVector();//Listlist=ne

1 / 12
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功