⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atm.txt

📁 该文件是用java开发工具编写的小型应用程序
💻 TXT
字号:
import java.sql.*;
import java.awt.*;

public class DataBC
{	
	static Connection conn;
	static Statement stmt;
	static ResultSet rs;   //接收结果集
	static int i;                 //接收结果响应行数
	
	static String userName,userPsw,tel;
	static int id,mon,id2;
	static int id_ZH;  //转帐id
	
	DataBC()
	{
		//功能:加载JDBC驱动
		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");	//加载驱动
			conn=DriverManager.getConnection("jdbc:odbc:database");
			stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
		}
		catch(Exception e)
		{
			e.getMessage();
		}
	}
	
	public static ResultSet select_All(int user_Id, String user_Password)  //登陆
	{
		id=user_Id;
		userPsw=user_Password;
		try
		{
			
			rs=stmt.executeQuery("select * from ZhangHu where id="+id+" And userpsw='"+userPsw+"'");
			
			if(rs.next())
				return rs;
			else
				return null;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return rs;
		}
	}
	
	//开户
	public static String insert_User(String userName,String userPsw,String money,String tel,String IdNumber,String address)
	{
		mon=Integer.parseInt(money);
		try
		{
			rs=stmt.executeQuery("select id from ZhangHu");
			while(rs.next())
			{
				id2=rs.getInt("id");
		    }
		    
			i=stmt.executeUpdate("insert into ZhangHu values("+(id2+1)+",

'"+userName+"','"+userPsw+"',"+mon+",'"+tel+"','"+IdNumber+"','"+address+"')");
			
			return ("开户成功!您的帐号为:"+(id2+1)+"   帐户余额为:"+String.valueOf(mon)+"元");
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return e.getMessage();
		}
		
	}
	
	public static ResultSet select_Money(int id)  //查询余额
	{
		try
		{
			
			rs=stmt.executeQuery("select * from ZhangHu where id="+id);
			
			rs.next();
			return rs;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return rs;
		}
	}
	
	public static int get_Money(int id1, int money)  //取款
	{
		id=id1;
		mon=money;
		try
		{
			rs=stmt.executeQuery("select mon from ZhangHu where id="+id);
			rs.next();
			int mon2=rs.getInt("mon");
			
			if(mon2>mon)
			{
			    i=stmt.executeUpdate("update ZhangHu set mon="+(mon2-mon)+" where id="+id);
			    return i;
			}
			else
			    return -1;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return 0;
		}
	}
	
	public static int save_Money(int id1, String money)  //存款
	{
		id=id1;
		mon=Integer.parseInt(money);
		try
		{
			rs=stmt.executeQuery("select mon from ZhangHu where id="+id);
			rs.next();
			int mon2=rs.getInt("mon");
			
			i=stmt.executeUpdate("update ZhangHu set mon="+(mon2+mon)+" where id="+id);
			
			return i;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return 0;
		}
	}
	
	public static int remove_Money(int id1, String money, String id2)  //转帐
	{
		id=id1;
		mon=Integer.parseInt(money);
		id_ZH=Integer.parseInt(id2);
		try
		{
			rs=stmt.executeQuery("select mon from ZhangHu where id="+id);
			rs.next();
			int mon1=rs.getInt("mon"); 
			
			rs=stmt.executeQuery("select mon from ZhangHu where id="+id_ZH);
			if(rs.next())
			{
			    int mon2=rs.getInt("mon");
			    		    
				if(mon1>mon)
				{
				    i=stmt.executeUpdate("update ZhangHu set mon="+(mon1-mon)+" where id="+id);
				    int j=stmt.executeUpdate("update ZhangHu set mon="+(mon2+mon)+" where id="+id_ZH);
				    return i;
				}
				else
				    return -1;	
		    }
		    else
		        return -2;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return 0;
		}
	}
	
	public static int delete_User(String id_user, String password)  //销户
	{
		id=Integer.parseInt(id_user);
		try
		{
			rs=stmt.executeQuery("select userpsw from ZhangHu where id="+id+" And userpsw='"+password+"'");
			if(rs.next())
			{
				try
				{
					i=stmt.executeUpdate("delete from ZhangHu where id="+id+" And userpsw='"+password+"'");
					return i;
				}
				catch(Exception e)
				{
					return -2;
				}
			}
		    else
				return -1;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return -2;
		}
	}
	
	public static int update_Information(String id_user, String tel, String address)  
//更新用户信息
	{
		id=Integer.parseInt(id_user);
		try
		{
			i=stmt.executeUpdate("update ZhangHu set tel='"+tel+"', address='"+address+"' where id="+id);
			
			return i;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return 0;
		}
	}
	
	public static int update_Password(int id, String password1, String password2)  //修改密码
	{
		try
		{
			rs=stmt.executeQuery("select userpsw from ZhangHu where id="+id+" And userpsw='"+password1+"'");
		
			if(rs.next())
			{
				try
				{
					i=stmt.executeUpdate("update ZhangHu set userpsw='"+password2+"' where id="+id);
					
					return i;
				}
				catch(Exception e)
				{
					e.printStackTrace();
					return 0;
				}
		    }
		    else
				return -1;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return -2;
		}
	}
	
	public static void close()
	{
		try
		{
			conn.close();
		}
		catch(Exception e)
		{
			e.getMessage();
		}
	}	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -