一个简单的小型应用,用于模拟银行存取。

基于java多线程,GUI、操作数据库,客服端服务端。

GUI界面的代码:

登录界面

package com.Gui;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.shujuku.*;import javax.swing.*;
public class DengluActionEvent extends JFrame implements ActionListener{ JTextField  inputText1;JPasswordField inputText2;JPanel p1,p2,p3;JLabel title_1,user_1,password_1;JButton button1,button2;JButton button3 = new JButton("注销账户");JButton button4 = new JButton("管理登录");public DengluActionEvent() {inputText1= new JTextField(10);inputText2 = new JPasswordField();title_1 = new JLabel("银行系统");button1 = new JButton("登录");button2= new JButton("注册"); user_1= new JLabel("用户名");password_1 = new JLabel("密码");inputText2.setEchoChar('*');user_1.setBounds(60,100,60,35);password_1.setBounds(60,150,60,35);inputText1.setBounds(111,100,200,40);inputText2.setBounds(111,150,200,40);button1.setBounds(120,210,75,30);button2.setBounds(210,210,75,30);button3.setBounds(100,260,90,30);button4.setBounds(210,260,90,30);title_1.setBounds(150,50,150,30);title_1.setFont(new Font("宋体",Font.BOLD,18));setBounds(100,100,460,360);setResizable(true);setLayout(null);setVisible(true);add(title_1);add(inputText1);add(inputText2);add(password_1);add(user_1);add(button2);add(button1);add(button3);add(button4);button1.addActionListener(this);button2.addActionListener(this);button3.addActionListener(this);button4.addActionListener(this);setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}  public void actionPerformed(ActionEvent e) {   if(e.getSource()==button1) {isLogin();//JOptionPane.showMessageDialog(this, "登录成功");    }else if(e.getSource()==button2) {new RegisterActionEvent();this.setVisible(false);}if(e.getSource()==button3) {new DeleteUser();dispose();}if(e.getSource()==button4) {if((inputText1.getText().equals("0"))&&(inputText2.getText().equals("0"))){      //管理登录   new ContralUser();dispose();}else  {JOptionPane.showMessageDialog(this, "密码错误!!!");}}
}void isLogin(){SelectShujuku database=new SelectShujuku();String LoginID =inputText1.getText();String password=new String(inputText2.getPassword());String userID=database.getDatabySql("select id from user where id="+LoginID,"id");       //从数据库导出登录名String pswdDatabase=String.valueOf(database.getDatabySql(("select password from user where id="+userID ),"password"));  //从数据库导出密码if(password.equals(pswdDatabase)) { new HomepageActionEvent(userID).setVisible(true);dispose();}else {JOptionPane.showMessageDialog(this, "密码错误!!!");inputText1.setText("");inputText2.setText("");}}}

主页

package com.Gui;import com.shujuku.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.*;
public class HomepageActionEvent  extends JFrame implements ActionListener{ JButton button1, button2, button3, button4;JLabel title,balance,yuan;;JTextField inputField;public HomepageActionEvent (String userid) {setTitle("银行主页");title = new JLabel("银行主页");button1 =new JButton("取款");button2 =new JButton("存款");button3 =new JButton("转账");button4 =new JButton("退出");balance = new JLabel("你的余额为:");yuan= new JLabel("元");inputField = new JTextField();title.setFont(new Font("宋体",Font.BOLD,18));title.setBounds(200,10,100,30);balance.setBounds(150,150,100,30);button1.setBounds(0,50,60,35);button2.setBounds(423,50,60,35);button3.setBounds(0,300,60,35);button4.setBounds(423,300,60,35);inputField.setBounds(220,150,100,30);yuan.setBounds(320,150,100,30);setBounds(200,100,500,400);setResizable(false);setLayout(null);setVisible(true);add(title);add(button1);add(button2);add(button3);add(button4);add(balance);add(inputField);add(yuan);button1.addActionListener(new ActionListener() { //取钱public void actionPerformed(ActionEvent e) {new GetMoneyActionEvent(userid);dispose();}});button2.addActionListener(new ActionListener() {       //存钱public void actionPerformed(ActionEvent e) {new CunqianActionEvent(userid);dispose();}});button3.addActionListener(new ActionListener() {       //存钱public void actionPerformed(ActionEvent e) {new ZhuanzhangActionEvent(userid);dispose();}});button4.addActionListener(new ActionListener() { //取钱public void actionPerformed(ActionEvent e) {dispose();}});setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//显示框读出数据SelectShujuku database=new SelectShujuku(); //新建数据库对象String mymoney = database.getDatabySql("select mymoney from user where id= "+userid,"mymoney");  inputField.setText(mymoney); }  public void actionPerformed(ActionEvent e) {   }
}

存钱

package com.Gui;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import com.shujuku.*;public class CunqianActionEvent extends JFrame implements ActionListener{JLabel title = new JLabel("正在存钱");JLabel label = new JLabel("请输入存钱金额");JLabel yuan= new JLabel("元");JButton button1 = new JButton("确定");JButton button2 = new JButton("取消");JTextField inputField = new JTextField(10);public CunqianActionEvent(String userid) {label.setBounds(100,150,100,35);inputField.setBounds(200,150,100,35);title.setBounds(160,50,101,35);title.setFont(new Font("宋体",Font.BOLD,18));yuan.setBounds(300,150,100,35);button1.setBounds(120,200,100,35);button2.setBounds(250,200,100,35);setBounds(200,100,500,400);setResizable(false);setLayout(null);setVisible(true);add(yuan);add(inputField);add(label);add(title);add(button1);add(button2);// button1.addActionListener(this);button1.addActionListener(new ActionListener() {   //取钱public void actionPerformed(ActionEvent e) {String getmoney = inputField.getText();UpdateShujuku updata = new UpdateShujuku();String sql = "update user set mymoney=mymoney+"+getmoney+" where id="+userid;updata.Updata(sql);//JOptionPane.showMessageDialog(this, "存款成功");dispose();new HomepageActionEvent(userid);}});button2.addActionListener(new ActionListener() {     //取消按钮public void actionPerformed(ActionEvent e) {new HomepageActionEvent(userid);dispose();}});}public void actionPerformed(ActionEvent e) {   }
}

取钱

package com.Gui;import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.*;import com.shujuku.SelectShujuku;
import com.shujuku.UpdateShujuku;
public class GetMoneyActionEvent extends JFrame implements ActionListener{JLabel label = new JLabel("请输入取款金额:");JLabel label2 = new JLabel("正在取钱");JLabel yuan= new JLabel("元");JButton button1 = new JButton("确定");JButton button2 = new JButton("取消");JTextField inputField = new JTextField(10);public GetMoneyActionEvent(String userid) {label.setBounds(100,150,100,35);inputField.setBounds(200,150,100,35);label2.setBounds(160,50,101,35);label2.setFont(new Font("宋体",Font.BOLD,18));yuan.setBounds(300,150,100,35);button1.setBounds(120,200,100,35);button2.setBounds(250,200,100,35);setBounds(200,100,500,400);setResizable(false);setLayout(null);setVisible(true);add(yuan);add(inputField);add(label);add(label2);add(button1);add(button2);button1.addActionListener(new ActionListener() {   //取钱public void actionPerformed(ActionEvent e) {String jianmoney = inputField.getText();double get = Double.valueOf(jianmoney);UpdateShujuku updata = new UpdateShujuku();SelectShujuku database = new SelectShujuku();String mymoney = database.getDatabySql("select mymoney from user where id=" + userid, "mymoney");double yuanlai = Double.valueOf(mymoney);if(yuanlai<get) {JOptionPane.showMessageDialog(null, "余额不足!", "出错", JOptionPane.ERROR_MESSAGE);}else {String sql = "update user set mymoney=mymoney-"+jianmoney+" where id="+userid;updata.Updata(sql);//JOptionPane.showMessageDialog(null, "存款成功");dispose();new HomepageActionEvent(userid);}}});button2.addActionListener(new ActionListener() {     //取消按钮public void actionPerformed(ActionEvent e) {new HomepageActionEvent(userid);dispose();}});}public void actionPerformed(ActionEvent e) {   }
}

注册

package com.Gui;import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import com.shujuku.*;public class RegisterActionEvent extends JFrame implements ActionListener{ JTextField  inputText1,inputText3,inputText4,inputText5;JPasswordField inputText2;JPanel p1,p2,p3;JTextArea textShow;JLabel title,user,password,id,shenfen,name;JComboBox root_1 =new JComboBox();JButton button1;public RegisterActionEvent() {setTitle("注册银行账户");inputText1= new JTextField(10);inputText2 = new JPasswordField(6);inputText3= new JTextField(10);inputText4= new JTextField(10);inputText5= new JTextField(10);title = new JLabel("注册银行账号");button1 = new JButton("注册");user= new JLabel("用户名");name= new JLabel("姓名");title = new JLabel("注册银行账号");password = new JLabel("密码");id = new JLabel("身份证号码");shenfen = new JLabel("注册类型");root_1.addItem("用户");root_1.addItem("管理员");inputText2.setEchoChar('*');name.setBounds(60,150,60,35);//姓名user.setBounds(60,100,60,35);//idpassword.setBounds(60,200,60,35);//密码id.setBounds(20,250,80,35);//身份证号shenfen.setBounds(50,300,60,35);//类型inputText1.setBounds(111,100,200,40);//idinputText2.setBounds(111,200,200,40);//密码inputText3.setBounds(111,150,200,40);//姓名inputText4.setBounds(111,250,200,40);//身份证号码//inputText5.setBounds(105,200,200,40);root_1.setBounds(111,300,200,40);button1.setBounds(150,350,75,30);title.setBounds(150,50,150,30);title.setFont(new Font("宋体",Font.BOLD,18));setBounds(200,100,500,600);setResizable(true);setLayout(null);setVisible(true);add(title);add(inputText1);add(inputText2);add(inputText3);add(inputText4);add(name);add(password);add(user);add(shenfen);add(button1);add(id);add(root_1); button1.addActionListener(this);setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}  public void actionPerformed(ActionEvent e) {   if(e.getSource()==button1) {String sid = inputText1.getText();String spassword = inputText2.getText();String sname = inputText3.getText();String sshenfen = inputText4.getText();String monney = "0";SelectShujuku database=new SelectShujuku();String LoginID =inputText1.getText();//查询是否有相同的用户名String userID=database.getDatabySql("select id from user where id="+LoginID,"id");       //从数据库导出登录名if(LoginID.equals(userID)) {JOptionPane.showMessageDialog(this, "注册失败,有相同用户名");return ;}InsertShujuku inser = new InsertShujuku();String sql1 = "insert into user(id,password,name,shenfen,mymoney)"+"value('"+sid+"','"+spassword+"','"+sname+"','"+sshenfen+"','"+monney+"')";inser.Insert(sql1);JOptionPane.showMessageDialog(this, "注册成功");new DengluActionEvent();      }}
}

转账

package com.Gui;import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;import com.shujuku.SelectShujuku;
import com.shujuku.UpdateShujuku;public class ZhuanzhangActionEvent extends JFrame implements ActionListener {JLabel title = new JLabel("正在转账");JLabel label1 = new JLabel("请输入转账账号");JLabel label2 = new JLabel("请输入转账金额");JLabel yuan = new JLabel("元");JButton button1 = new JButton("确定");JButton button2 = new JButton("取消");JTextField inputField1 = new JTextField(10);JTextField inputField2 = new JTextField(10);public ZhuanzhangActionEvent(String userid) {label1.setBounds(100, 100, 100, 35);label2.setBounds(100, 150, 100, 35);inputField1.setBounds(200, 100, 100, 35);inputField2.setBounds(200, 150, 100, 35);title.setBounds(160, 50, 101, 35);title.setFont(new Font("宋体", Font.BOLD, 18));yuan.setBounds(300, 150, 100, 35);button1.setBounds(120, 200, 100, 35);button2.setBounds(250, 200, 100, 35);setBounds(200, 100, 500, 400);setResizable(false);setLayout(null);setVisible(true);add(yuan);add(inputField1);add(inputField2);add(label1);add(label2);add(title);add(button1);add(button2);// 监听两个按钮button1.addActionListener(new ActionListener() { // 确定按钮public void actionPerformed(ActionEvent e) {UpdateShujuku updata = new UpdateShujuku();SelectShujuku database = new SelectShujuku();String snum = inputField1.getText();if (snum.equals(userid)) {JOptionPane.showMessageDialog(null, "不能给自己转账", "出错", JOptionPane.ERROR_MESSAGE);} else {String sentmoney = inputField2.getText();double sent = Double.valueOf(sentmoney);String mymoney = database.getDatabySql("select mymoney from user where id=" + userid, "mymoney");double yuanlai = Double.valueOf(mymoney);if (sent > yuanlai) {JOptionPane.showMessageDialog(null, "余额不足!", "出错", JOptionPane.ERROR_MESSAGE);} else {String sql1 = "update user set mymoney=mymoney-" + sentmoney + " where id=" + userid;// 自己的updata.Updata(sql1);String sql2 = "update user set mymoney=mymoney+" + sentmoney + " where id=" + snum;// 转给用户的idupdata.Updata(sql2);new HomepageActionEvent(userid);dispose();}}}});button2.addActionListener(new ActionListener() {// 退出按钮public void actionPerformed(ActionEvent e) {new HomepageActionEvent(userid);dispose();}});}public void actionPerformed(ActionEvent e) {}
}

删除用户

package com.Gui;import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import com.shujuku.*;public class DeleteUser extends JFrame implements ActionListener {JLabel title = new JLabel("正在注销用户");JLabel deteleuserid = new JLabel("请输入注销的用户id:");JLabel deteleuserpassword = new JLabel("请输入注销的用户密码:");JTextField inputField1 = new JTextField(10);JTextField inputField2 = new JTextField(10);JButton button1= new JButton("确定删除");JButton button2 = new JButton("取消");public DeleteUser() {title.setBounds(150,50,130,50);title.setFont(new Font("宋体",Font.BOLD,18));deteleuserid.setBounds(80,100,140,40);deteleuserpassword.setBounds(80,160,140,40);inputField1.setBounds(210,100,100,40);inputField2.setBounds(210,160,100,40);button1.setBounds(100,210,100,40);button2.setBounds(220,210,60,40);setBounds(200,100,500,350);setResizable(false);setLayout(null);setVisible(true);add(title);add(deteleuserid);add(deteleuserpassword);add(inputField1);add(inputField2);add(button1);add(button2);button1.addActionListener(this);button2.addActionListener(this);setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e) {if(e.getSource()==button1) {DeleteShuju dete = new DeleteShuju();String LoginID = inputField1.getText();String userpassword = inputField2.getText();SelectShujuku database=new SelectShujuku();String userID=database.getDatabySql("select id from user where id="+LoginID,"id");     //从数据库导出登录名String pswdDatabase=String.valueOf(database.getDatabySql(("select password from user where id="+userID ),"password"));//从数据库导出密码if(userpassword.equals(pswdDatabase)) {String sql ="delete from user where id="+LoginID;dete.deleteUser(sql);JOptionPane.showMessageDialog(this, "删除成功");}else {JOptionPane.showMessageDialog(this, "密码错误!无法删除");}}if(e.getSource()==button2) {new DengluActionEvent();dispose();}}}

管理显示

package com.Gui;import java.sql.*;
import javax.swing.*;
import com.shujuku.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;public class ContralUser {public ContralUser(){JFrame jFrame  = new JFrame("用户信息");jFrame.setSize(500,500);//大小jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);jFrame.setLocationRelativeTo(null);//居中jFrame.setResizable(false);//创建面板JPanel panel = new JPanel();//表格Chaxun search = new Chaxun();Object[][] database1 = search.getDatabySql("select id,name,shenfen,mymoney,password from user");Object[] col = {"用户名","用户姓名","身份ID","存款"};JTable table = new JTable(database1, col);//表头和内容放入表table.setRowHeight(20);//设置行高table.setPreferredScrollableViewportSize(new Dimension(400,300));//整张表的大小JScrollPane scrollPane = new JScrollPane(table);//给表整一个滑轮panel.add(scrollPane);//把表放入面板//组件JButton button = new JButton("返回登录");button.setBounds(200,200,100,100);panel.add(button);button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {if(e.getSource()==button) {jFrame.dispose();new DengluActionEvent();}}});//显示jFrame.setContentPane(panel);jFrame.setVisible(true);}public static void main(String args[]) {new ContralUser();}
}

客服端,服务器

客服端

package com.loginServer;import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.Gui.*;public class LoginClient extends JFrame implements Runnable, ActionListener {Socket socket = null;DataInputStream in = null;DataOutputStream out = null;Thread thread;JTextField inputText1;JPasswordField inputText2;JPanel p1, p2, p3;JLabel title_1, user_1, password_1;JButton button1, button2;JButton button3 = new JButton("注销账户");JButton button4 = new JButton("管理登录");JButton connection = new JButton("连接服务器");public LoginClient() {socket = new Socket();inputText1 = new JTextField(10);inputText2 = new JPasswordField();title_1 = new JLabel("银行系统");button1 = new JButton("登录");button1.setEnabled(false);// 不可见button2 = new JButton("注册");button2.setEnabled(false);// 不可见user_1 = new JLabel("用户名");password_1 = new JLabel("密码");inputText2.setEchoChar('*');user_1.setBounds(60, 100, 60, 35);password_1.setBounds(60, 150, 60, 35);inputText1.setBounds(111, 100, 200, 40);inputText2.setBounds(111, 150, 200, 40);button1.setBounds(120, 210, 75, 30);button2.setBounds(210, 210, 75, 30);button3.setBounds(100, 260, 90, 30);button4.setBounds(210, 260, 90, 30);title_1.setBounds(150, 50, 150, 30);title_1.setFont(new Font("宋体", Font.BOLD, 18));connection.setBounds(150, 0, 100, 40);setBounds(100, 100, 460, 360);button3.setEnabled(false);// 不可见button4.setEnabled(false);// 不可见setResizable(true);setLayout(null);setVisible(true);add(title_1);add(inputText1);add(inputText2);add(password_1);add(user_1);add(button2);add(button1);add(button3);add(button4);add(connection);button1.addActionListener(this);button2.addActionListener(this);button3.addActionListener(this);button4.addActionListener(this);connection.addActionListener(this);inputText1.addActionListener(this);thread = new Thread(this);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);validate();}public void actionPerformed(ActionEvent e) {if (e.getSource() == connection) {try {if (socket.isConnected()) {} else {InetAddress address = InetAddress.getByName("127.0.0.1");InetSocketAddress socketAddress = new InetSocketAddress(address, 2011);socket.connect(socketAddress);//连接in = new DataInputStream(socket.getInputStream());out = new DataOutputStream(socket.getOutputStream());button1.setEnabled(true);button2.setEnabled(true);button3.setEnabled(true);button4.setEnabled(true);thread.start();}} catch (IOException ee) {socket = new Socket();}} else if (e.getSource() == button1) {String s = inputText1.getText();if (s != null) {try {out.writeUTF("id:" + s);} catch (IOException e1) {}}}if (e.getSource() == button2) {new RegisterActionEvent();this.setVisible(false);}if (e.getSource() == button3) {new DeleteUser();dispose();}if (e.getSource() == button4) {if ((inputText1.getText().equals("0")) && (inputText2.getText().equals("0"))) { // 管理登录new ContralUser();dispose();} else {JOptionPane.showMessageDialog(this, "密码错误!!!");}}}public void run() {String s = null;while (true) {try {s = in.readUTF();String password = new String(inputText2.getPassword());String userID = inputText1.getText();if (password.equals(s)) {new HomepageActionEvent(userID).setVisible(true);dispose();} else {JOptionPane.showMessageDialog(this, "密码错误!!!");inputText1.setText("");inputText2.setText("");}} catch (IOException e) {System.out.println("与服务器已断开");break;}}}public static void main(String[] args) {new LoginClient();}
}

服务器:

package com.loginServer;import java.io.*;
import java.net.*;
import java.sql.*;public class Server {public static void main(String args[]) {String url = "jdbc:mysql://localhost:3306/bank?" + "useSSL=true&serverTimezone=UTC";String user = "root";String password = "654122";try {Class.forName("com.mysql.cj.jdbc.Driver");} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}Connection con;PreparedStatement sqlOne = null;ResultSet rs;try {con = DriverManager.getConnection(url, user, password);sqlOne = con.prepareStatement("select * from user where id = ?");//?为占位符,以便后面设置} catch (SQLException e) {}ServerSocket server = null;//服务器Runnable target;Thread threadForClient = null;Socket socketOnServer = null;//客服端接口while (true) {try {server = new ServerSocket(2011);} catch (IOException e1) {System.out.println("正在监听");}try {System.out.println("等待客户呼叫");socketOnServer = server.accept();//接受用户发送的信息System.out.println("客户的地址:" + socketOnServer.getInetAddress());//得到客服的地址} catch (IOException e) {System.out.println("正在等待客户");}if (socketOnServer != null) {target = new Target(socketOnServer, sqlOne);threadForClient = new Thread(target);threadForClient.start();//开启线程}}}
}
package com.loginServer;import java.net.*;
import java.io.*;
import java.sql.*;public class Target extends Thread implements Runnable {Socket socket;DataOutputStream out = null;DataInputStream in = null;PreparedStatement sqlOne;boolean boo = false;Target(Socket t, PreparedStatement sqlOne) {socket = t;this.sqlOne = sqlOne;try {out = new DataOutputStream(socket.getOutputStream());in = new DataInputStream(socket.getInputStream());} catch (IOException e) {System.out.println(e);}}public void run() {ResultSet rs = null;while (true) {try {String str = in.readUTF();if (str.startsWith("id:")) {str = str.substring(str.indexOf(":") + 1);// 用:分隔字符串sqlOne.setString(1, str);rs = sqlOne.executeQuery();}while (rs.next()) {boo = true;String id = rs.getString(1);String key = rs.getString(3);// 密码out.writeUTF(key);}if (boo == false)out.writeUTF("无此用户");} catch (IOException e) {System.out.println("客户离开" + e);return;} catch (SQLException e) {System.out.println(e);}}}
}

数据库部分

连接数据库

package com.shujuku;import java.sql.*;public class ConnectShujuku {//连接数据库Connection con;Statement statement;ResultSet rs;private String uri="jdbc:mysql://localhost:3306/bank?"+"useSSL=true&serverTimezone=UTC";private String user="root";private String password ="654122";public ConnectShujuku(){}public void Jiazaicon() {//加载驱动try {Class.forName("com.mysql.cj.jdbc.Driver");} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}try { // 连接数据库con = DriverManager.getConnection(uri, user,password);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();System.out.println("连接失败!");}}
}

查询所有,存在数组里

package com.shujuku;import java.sql.*;public class Chaxun {//查询用户所有的信息Object[][] database = new String[20][5];ConnectShujuku data = new ConnectShujuku();//创建数据库连接对象public Object[][] getDatabySql(String sql){data.Jiazaicon();//连接数据库try {// 建立Statement对象data.statement = data.con.createStatement();// Statement createStatement() 创建一个 Statement 对象来将 SQL 语句发送到数据库。// 执行数据库查询语句data.rs = data.statement.executeQuery(sql);for(int i = 0;data.rs.next();i++) {database[i][0]=  data.rs.getString("id");database[i][1]=  data.rs.getString("name");database[i][4]=  data.rs.getString("password");database[i][2]=  data.rs.getString("shenfen");database[i][3]=  data.rs.getString("mymoney");}return database;}catch (SQLException e) {e.printStackTrace();System.out.println("数据读取异常");}return null;}
}

查询单个属性组

package com.shujuku;import java.sql.*;public class SelectShujuku {// 查询数据并返回指定列ConnectShujuku data = new ConnectShujuku();public String getDatabySql(String sql, String item) {data.Jiazaicon();try {// 建立Statement对象data.statement = data.con.createStatement();// Statement createStatement() 创建一个 Statement 对象来将 SQL 语句发送到数据库。// 执行数据库查询语句data.rs = data.statement.executeQuery(sql);// 语句,该语句返回单个 ResultSet 对象while (data.rs.next()) {// rs.next()返回布尔值,且光标跳转到下一行return (data.rs.getString(item).trim());// 此处适应于只需要取一个具体数据的情况,如取具体用户对应的密码。完整代码中还有计算数据长度,取多个数据的方法。}if (data.rs != null) {// 读取数据不为空后就关闭data.rsdata.rs.close();data.rs = null;}if (data.statement != null) {// sql语句正确后关闭statementdata.statement.close();data.statement = null;}if (data.con != null) {// 连接成功后,用于关闭连接data.con.close();data.con = null;}return "";} catch (SQLException e) {e.printStackTrace();System.out.println("数据读取异常");}return " ";}
}

更新数据库内容

package com.shujuku;
import java.sql.*;
public class UpdateShujuku {//用于存取钱ConnectShujuku data = new ConnectShujuku();public void Updata(String sql) {data.Jiazaicon();Statement stmt;try {stmt = data.con.createStatement();//创建一个Statement对象stmt.executeUpdate(sql);//执行sql语句data.con.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}
}

插入数据

package com.shujuku;import java.sql.*;public class InsertShujuku {// 插入用户信息ConnectShujuku data = new ConnectShujuku();public void Insert(String sql1) {data.Jiazaicon();String sql = sql1;Statement stmt;try {stmt = data.con.createStatement();// 创建一个Statement对象stmt.executeUpdate(sql);// 执行sql语句System.out.println("插入到数据库成功");data.con.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();} }}

删除用户

package com.shujuku;import java.sql.*;public class DeleteShuju {//删除用户信息ConnectShujuku data = new ConnectShujuku();public void deleteUser(String sql1) {data.Jiazaicon();//加载驱动并连接数据库Statement stmt;try {stmt = data.con.createStatement();//创建一个Statement对象stmt.executeUpdate(sql1);//执行sql语句System.out.println("数据删除成功");data.con.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}

好像数据库增删改查可以直接用一个函数实现,可以尝试改一下。

数据库的版本是8.0.27,密码是654122

jdk是16.0的。

以下是数据库里的内容:

运行

首先运行sever,连接服务器

然后是运行客服端

输入密码 进入主页

(银行简单的管理系统)java实训小型应用开发——数据库,GUI、客服端相关推荐

  1. 简单计算器(Java实训)

    简单计算器(Java实训) 实训目的: 掌握 Java GUI 开发中的布局管理和事件处理机制. 实训要求: (1)要使用 java 的 GUI 设计出计算器界面.(2)通过界面 按钮,可以实现整数或 ...

  2. 【项目实训】个人开发记录博客

    神经网络模型以及数据问题 dataset和label可以用TensorDataset来转换为一个可以放入DataLoader的类 permute维度换位,为了适配网络参数输入顺序 解决问题,之前一直用 ...

  3. Java实训项目--小型书店管理系统(ssm框架)

    系列文章目录 MyBatis专栏: 一:Java实训项目–小型图书管理系统(ssm框架) 二:"spring与mybatis整合"考试题目测试与解析 三:"SSM框架整合 ...

  4. JAVA实训项目:银行网银系统管理平台(含源码)

    JAVA实训项目:银行网银系统管理平台(含源码) 文章目录 JAVA实训项目:银行网银系统管理平台(含源码) 前言 一.项目功能需求描述以及相关技术的应用 相关技术应用 二.设计过程 系统流程图 1. ...

  5. Java实训学生信息_(java实训)学生信息管理系统.doc

    您所在位置:网站首页 > 海量文档 &nbsp>&nbsp计算机&nbsp>&nbspJava (java实训)学生信息管理系统.doc9页 本文档一 ...

  6. 2020年Java实训项目【GUI学生信息管理系统】目录

    Java实训项目1:GUI学生信息管理系统 - 实训概述 Java实训项目2:GUI学生信息管理系统 - 系统概述 Java实训项目3:GUI学生信息管理系统 - 涉及知识点 Java实训项目4:GU ...

  7. Java实训项目:GUI学生信息管理系统(2019)【下】

    Java实训项目:GUI学生信息管理系统(2019)[下] 本篇目录 六.实现步骤 13.应用程序类 14.窗口界面类(JFrame)

  8. Java实训项目:GUI学生信息管理系统(2019)【中】

    Java实训项目:GUI学生信息管理系统(2019)[中] 本篇目录 四.涉及知识点 1.Java基本语法 2.Java流程控制

  9. Java实训项目:GUI学生信息管理系统(2019)【上】

    Java实训项目:GUI学生信息管理系统(2019)[上] 本篇目录 零.实训概述 1.实训目的 2.项目简介

最新文章

  1. TensorFlow领衔,七大深度学习框架大对比!
  2. ARM7与ARM9的区别
  3. 单摄像头+深度学习实现伪激光雷达,代码已开源
  4. 044_定义类或对象
  5. Ubuntu中root用户和user用户的相互切换
  6. java tif格式图片_java给tif格式图片加文字水印?
  7. 大型分布式C++框架《四:netio之请求包中转站 上》
  8. Spring Cloud:查看注册到Eureka上的应用信息
  9. 计算机组成原理实验软件仿真系统_计算机系统组成原理(基础)
  10. 单点登录多点注销shiro的简单实现
  11. 深度学习2.0-23.Keras高层接口之CIFAR10自定义网络实战
  12. Finalize/Dispose资源清理模式
  13. 【路径规划】基于matlab GUI改进的遗传算法机器人栅格地图避障路径规划【含Matlab 703期】
  14. sw4stm32开发stm32
  15. 挑战程序设计竞赛——Ants(POJ No.1852)
  16. python考勤记录_python做考勤统计
  17. 打开QQ音乐检测不到声卡
  18. cad选择集的问题(VBA )
  19. ORACLE应用产品和SAP、SSA、SYMIX产品的比较分析
  20. GeoTool常见问题

热门文章

  1. URL 是什么?(2007-09-20 23:52:53| 分类: 网络技术)
  2. 经常光顾的IOS开发网站
  3. 服务器芯片top10,国内云服务器排名top10
  4. python程序设计黄锐军测验答案_Python程序设计
  5. Nginx源码学习(一):nginx进程模型解析
  6. Protel常用元器件封装总结
  7. Word文档很乱怎么办 杂乱的文章word排版教程
  8. 我,阿里的程序员,工作5年,揭秘阿里员工的真实收入和工作经历
  9. vscode主题颜色设置为light,代码颜色花里胡哨
  10. hasp运行不成功_条码打印软件安装提示HASP错误代码处理方法