JavaGUI编程——ATM项目包含源码和程序使用说明

2019-01-24

本程序由java编写,包含了数据库,GUI等知识。

压缩文件中有程序源码,数据库文件,程序使用说明。

程序主要代码如下:

/*

*接口

*/

public ResultSet Select(String x);                  //查询
 public void withDrawal(float x);                    //取款
 public void Remove(String x,float y);               //转账
 public void Insert(float x);                        //存款
 public boolean Land(String x,String y);    

/*

*实现

*/

package Link_ATM;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

import Windows_ATM.Windows_land;

public  class Operate implements Link_Method{

 @Override
 public ResultSet Select(String x){                  //查询
  Link link=new Link();
  Statement stmt=null;
  ResultSet rs=null;
  ResultSet vs = null;
  Connection conn=null;
  try {
   conn=link.Link();
   stmt=(Statement) conn.createStatement();
  } catch (ClassNotFoundException e) {
   
   e.printStackTrace();
  } catch (SQLException e) {
   
   e.printStackTrace();
  }
  String sql="select * from user where Id= "+x;
  try {
   rs=stmt.executeQuery(sql);
   vs=rs;
  } catch (SQLException e) {
   
   e.printStackTrace();
  }
  return vs;
  
 }

 @Override
 public void withDrawal(float x) {                      //取款
  Link link=new Link();
  Statement stmt=null;
  ResultSet rs=null;
  Connection conn=null;
  float g=0f;
  try {
   conn=link.Link();
   stmt=(Statement) conn.createStatement();
  } catch (ClassNotFoundException e) {
   
   e.printStackTrace();
  } catch (SQLException e) {
   
   e.printStackTrace();
  }
  String sql="select Money from user where Id= "+Windows_land.x;
  try {
   rs=stmt.executeQuery(sql);
  } catch (SQLException e) {
   
   e.printStackTrace();
  }
  try {
   while(rs.next()) {
    float money =rs.getFloat("Money");
    if(money>=x) {
     g=money-x;
     
     
//     取款成功!
    }
   }
  } catch (SQLException e) {
   // TODO 自动生成的 catch 块
   e.printStackTrace();
  }
  String  in="UPDATE user SET Money = '"+g+"'WHERE Id = '"+Windows_land.x+"'" ;
  try {
   stmt.executeUpdate(in);
  } catch (SQLException e) {
   // TODO 自动生成的 catch 块
   e.printStackTrace();
  }
  
 }

 
 
 
 
 
 
 
 @Override
 public void Remove(String x,float y) {                     //转账
  

  /*
   * 有bug 数据库中没有目标用户时 也会进行转账操作 扣除源账户资金
   */
  
  
  
  Link link=new Link();
  Statement stmt=null;
  ResultSet rs=null;
  Connection conn=null;
  float z=0f;                                              //当前账户金额
  float out=0f;                                            //对方账户金额
  try {
   conn=link.Link();
   stmt=(Statement) conn.createStatement();
  } catch (ClassNotFoundException e) {
   
   e.printStackTrace();
  } catch (SQLException e) {
   
   e.printStackTrace();
  }
  
  
  
  /*
  * 查询转账用户是否存在
  */
  
  String pd="select Name from user where Id="+x; 
 
  try {
   ResultSet result=stmt.executeQuery(pd);
   
   
   result.next();
   
   if(!result.getString("Name").equals(""))
   {
   
   
   
   String sql1="select * from user where Id= "+Windows_land.x;
   try {
    rs=stmt.executeQuery(sql1);
   } catch (SQLException e) {
    
    e.printStackTrace();
   }
   try {
    while(rs.next()) {
     float money =rs.getFloat("Money");
     if(money>=y) {
      z=money-y;
      
      
//      余额足够转账
     }
    }
   } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
   }
   
  /*
   * 当前用户金额减少
   */
   
   
   String  in="UPDATE user SET Money = '"+z+"'WHERE Id = '"+Windows_land.x+"'" ;
   try {
    stmt.executeUpdate(in);
   } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
   }
   
  /*
   * 增加对方账户金额
   */
   
   String out2="select * from user where Id= "+x;
   try {
    rs=stmt.executeQuery(out2);
   } catch (SQLException e) {
    
    e.printStackTrace();
   }
   try {
    while(rs.next()) {
     float money =rs.getFloat("Money");
     z=money+y;
                                                //      增加余额

    }
   } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
   }
   
   String  out1="UPDATE user SET Money = '"+z+"'WHERE Id = '"+x+"'" ;
   
   try {
    stmt.executeUpdate(out1);
   } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
   }
   
   
   }
   else {
    JOptionPane.showMessageDialog(new JFrame().getContentPane(), "无此账户!");
   }
   
   
   
  } catch (SQLException e) {
   e.printStackTrace();
  }
  
  
  
 }

 
 
 
 
 
 @Override
 public void Insert(float x) {                              //存款
  Link link=new Link();
  Statement stmt=null;
  ResultSet rs=null;
  Connection conn=null;
  float y = 0;
  try {
   conn=link.Link();
   stmt=(Statement) conn.createStatement();
  } catch (ClassNotFoundException e) {
   
   e.printStackTrace();
  } catch (SQLException e) {
   
   e.printStackTrace();
  }
  String sql="select Money from user where Id= "+Windows_land.x;
  try {
   rs=stmt.executeQuery(sql);
  } catch (SQLException e) {
   
   e.printStackTrace();
  }
  try {
   while(rs.next()) {
    y=rs.getFloat("Money");
    y+=x;                                        //存款
   }
  } catch (SQLException e) {
   e.printStackTrace();
  }
  String in="UPDATE user SET Money = '"+y+"'WHERE Id = '"+Windows_land.x+"'" ;
  try {
   stmt.executeUpdate(in);
  } catch (SQLException e) {
   
   e.printStackTrace();
  }
  
 }

 @Override
 public boolean Land(String x, String y) {             //登陆
  
  Link link=new Link();
  Connection conn=null;
  Statement stmt=null;
  ResultSet rs=null;
  boolean back=false;
  String sql="select * from user where Id="+x;
  try {
   conn=link.Link();
   stmt=(Statement)conn.createStatement();
   rs=stmt.executeQuery(sql);
  } catch (ClassNotFoundException | SQLException e) {
   e.printStackTrace();
  }
  try {
   while(rs.next()) {
    
    if(rs.getString("Password").equals(y)) {
     
     back=true;
    }
    else {
     
     back=false;
    }
   }
  } catch (SQLException e) {
   e.printStackTrace();
  }
  return back;
 }

}

程序运行截图

下载地址:链接:https://pan.baidu.com/s/1qOuYBUX7D2o\_2O3xwwi1-Q
提取码:7uht

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )