超市会员管理系统,数据库课程设计

这是一个使用Java Swing和SQL Server数据库实现的简单超市会员管理系统。系统包括会员信息管理、物品信息管理和优惠信息管理,实现了增删改查功能。界面通过JFrame布局,按钮触发事件来切换不同窗口并进行数据库操作。
摘要由CSDN通过智能技术生成

1.简单的java ui界面
2.配合数据库创建了三个表
3.三个表分别是会员信息管理,优惠政策,商品信息
4.会员信息,优惠政策管理都实现了数据库的增,删,改,查。
5.物品信息表只实现了数据的查找
6.使用的软件版本是idea2018,sqlsever2019,应该也是兼容sqlsever2008r2

不会运行可以私信
先放两张运行截图吧
只是使用了一个类直接复制上去就能运行非常方便
在这里插入图片描述
在这里插入图片描述

package 超市会员管理系统;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Vector;

public class caidan {
    JFrame win1=new JFrame("超市会员管理系统");
    JFrame win2=new JFrame("会员信息管理");
    JFrame win3=new JFrame("物品信息管理");
    JFrame win4=new JFrame("超市会员管理系统");
    JFrame win5=new JFrame("修改会员信息");
    JFrame win6=new JFrame("删除会员信息");
    JFrame win7=new JFrame("添加会员信息");
    JFrame win8=new JFrame("查询会员信息");
    JFrame win9=new JFrame("优惠管理");
    JFrame win10=new JFrame("优惠管理");
    JFrame win11=new JFrame("优惠管理");
    JFrame win12=new JFrame("优惠管理");
    JFrame win13=new JFrame("优惠管理");

    JButton btn1=new JButton("会员信息管理");
    JButton btn2=new JButton("物品信息管理");
    JButton btn3=new JButton("折扣信息管理");
    JButton btn4=new JButton("修改");
    JButton btn5=new JButton("添加");
    JButton btn6=new JButton("删除");
    JButton btn7=new JButton("返回");
    JButton btn8=new JButton("返回");
    JButton btn9=new JButton("返回");
    JButton btn10=new JButton("查询");
    JLabel label;
    public void win1(){

        win1.setLayout(null);
        win1.setVisible(true);
        win1.setBounds(500,500,600,400);
        btn1.setSize(140,40);
        btn1.setLocation(50,300);
        btn2.setSize(140,40);
        btn2.setLocation(200,300);
        btn3.setSize(140,40);
        btn3.setLocation(350,300);
        win1.add(btn1);
        win1.add(btn2);
        win1.add(btn3);
        btn1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                win1.setVisible(false);
                win2();

            }
        });
        btn2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                win1.setVisible(false);
                win3();

            }
        });
        btn3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                win1.setVisible(false);
                win9();

            }
        });

        label=new JLabel();
        label.setText("欢迎超市会员管理系统");
        label.setLocation(190,60);
        label.setSize(500, 200);
        win1.add(label);
    }

public void win2(){
    win2.setLayout(null);
    win2.setVisible(true);
    win2.setBounds(500,500,600,400);
    btn4.setSize(80,40);
    btn4.setLocation(10,300);
    btn5.setSize(80,40);
    btn5.setLocation(110,300);
    btn6.setSize(80,40);
    btn6.setLocation(210,300);
    btn7.setSize(80,40);
    btn7.setLocation(310,300);
    btn10.setSize(80,40);
    btn10.setLocation(410,300);
    win2.add(btn4);
    win2.add(btn5);
    win2.add(btn6);
    win2.add(btn7);
    win2.add(btn10);
    btn7.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win2.setVisible(false);
            win1();
        }
    });
    btn4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win2.setVisible(false);
            win5();
        }
    });
    btn5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win2.setVisible(false);
           win7();
        }
    });
    btn6.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win2.setVisible(false);
            win6();
        }
    });
    btn10.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win2.setVisible(false);
            win8();
        }
    });
}
public void win3(){
    win3.setLayout(null);
    win3.setVisible(true);
    win3.setBounds(500,500,600,400);

    btn8.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win3.setVisible(false);
            win1();
        }
    });

    JLabel lab1= new JLabel("需要查找物品编号");
    JLabel lab2= new JLabel("物品编号");
    JLabel lab3= new JLabel("物品名称");
    JLabel lab4= new JLabel("物品数量");
    JLabel lab5= new JLabel("物品价格");

    JTextField jtex1= new JTextField();
    JTextField jtex2= new JTextField();
    JTextField jtex3= new JTextField();
    JTextField jtex4= new JTextField();
    JTextField jtex5= new JTextField();

    lab1.setSize(80,30);
    lab1.setLocation(100,20);

    lab2.setSize(80,30);
    lab2.setLocation(100,70);

    lab3.setSize(80,30);
    lab3.setLocation(100,120);

    lab4.setSize(80,30);
    lab4.setLocation(100,170);


    lab5.setSize(80,30);
    lab5.setLocation(100,220);

    win3.add(lab1);
    win3.add(lab2);
    win3.add(lab3);
    win3.add(lab4);
    win3.add(lab5);

    jtex1.setSize(80,30);
    jtex1.setLocation(180,20);

    jtex2.setSize(80,30);
    jtex2.setLocation(180,70);

    jtex3.setSize(80,30);
    jtex3.setLocation(180,120);

    jtex4.setSize(80,30);
    jtex4.setLocation(180,170);

    jtex5.setSize(80,30);
    jtex5.setLocation(180,220);

    win3.add(jtex1);
    win3.add(jtex2);
    win3.add(jtex3);
    win3.add(jtex4);
    win3.add(jtex5);

    JButton bt1=new JButton("点击查找");
    JButton bt2=new JButton("点击返回");

    bt1.setSize(100,50);
    bt1.setLocation(400,100);
    bt2.setSize(100,50);
    bt2.setLocation(400,200);

    win3.add(bt1);
    win3.add(bt2);

    bt2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win3.setVisible(false);
            win1();
        }
    });
    bt1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String inputName=jtex1.getText();

            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                //加载对应的jdbc驱动
                String url="jdbc:sqlserver://localhost:1433; DatabaseName=supermaket";
                //配置连接字符串
                String user="sa";//sa超级管理员
                String password="123";//密码
                Connection conn=DriverManager.getConnection(url,user,password);
                //创建数据库连接对象
                Statement st=conn.createStatement();
                //创建SQL语句执行对象

                String  strSQL="(Select* from  dbo.wupin where 物品编号='"+inputName+"' )";
                ResultSet rs=st.executeQuery(strSQL);

                if(rs.next())
                {
                    jtex2.setText(rs.getString(1));
                    jtex3.setText(rs.getString(2));
                    jtex4.setText(rs.getString(3));
                    jtex5.setText(rs.getString(4));


                }
                else
                {
                    JOptionPane.showMessageDialog(null, "您查询的课程不存在,请重新输入");
                }
                conn.close();

                //关闭数据库连接
            }
            catch (ClassNotFoundException ex) {
                System.out.println("没有找到对应的数据库驱动类");
            }
            catch (SQLException ex) {
                System.out.println("数据库连接或者是数据库操作失败");
            }



        }
    });

    }
public void win4(){
    win4.setLayout(null);
    win4.setVisible(true);
    win4.setBounds(500,500,600,400);
    btn9.setSize(150,40);
    btn9.setLocation(225,300);
    win4.add(btn9);
    btn9.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win4.setVisible(false);
            win1();
        }
    });
}
public void win5(){
    win5.setLayout(null);
    win5.setVisible(true);
    win5.setBounds(500,500,600,400);

    JLabel lab1= new JLabel("姓名");
    JLabel lab2= new JLabel("性别");
    JLabel lab3= new JLabel("年龄");
    JLabel lab4= new JLabel("联系方式");
    JLabel lab5= new JLabel("编号");
    JLabel lab6= new JLabel("需要修改的姓名");

    JTextField jtex1= new JTextField();
    JTextField jtex2= new JTextField();
    JTextField jtex3= new JTextField();
    JTextField jtex4= new JTextField();
    JTextField jtex5= new JTextField();
    JTextField jtex6= new JTextField();


    lab1.setSize(80,30);
    lab1.setLocation(100,70);

    lab2.setSize(80,30);
    lab2.setLocation(100,120);

    lab3.setSize(80,30);
    lab3.setLocation(100,170);

    lab4.setSize(80,30);
    lab4.setLocation(100,220);


    lab5.setSize(80,30);
    lab5.setLocation(100,270);

    lab6.setSize(80,30);
    lab6.setLocation(100,20);


    win5.add(lab1);
    win5.add(lab2);
    win5.add(lab3);
    win5.add(lab4);
    win5.add(lab5);
    win5.add(lab6);

    jtex1.setSize(80,30);
    jtex1.setLocation(180,70);

    jtex2.setSize(80,30);
    jtex2.setLocation(180,120);

    jtex3.setSize(80,30);
    jtex3.setLocation(180,170);

    jtex4.setSize(80,30);
    jtex4.setLocation(180,220);

    jtex5.setSize(80,30);
    jtex5.setLocation(180,270);

    jtex6.setSize(80,30);
    jtex6.setLocation(180,20);

    win5.add(jtex1);
    win5.add(jtex2);
    win5.add(jtex3);
    win5.add(jtex4);
    win5.add(jtex5);
    win5.add(jtex6);

    JButton bt1=new JButton("点击修改");
    JButton bt2=new JButton("点击返回");

    bt1.setSize(100,50);
    bt1.setLocation(400,100);
    bt2.setSize(100,50);
    bt2.setLocation(400,200);

    win5.add(bt1);
    win5.add(bt2);

    bt2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win5.setVisible(false);
            win2();
        }
    });

    bt1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String Name=jtex6.getText();
            String updateName=jtex1.getText();
            String sex=jtex2.getText();
            String age=jtex3.getText();
            String number=jtex4.getText();
            String id=jtex5.getText();



            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                //加载对应的jdbc驱动
                String url="jdbc:sqlserver://localhost:1433; DatabaseName=supermaket";
                //配置连接字符串
                String user="sa";//sa超级管理员
                String password="123";//密码
                Connection conn=DriverManager.getConnection(url,user,password);
                //创建数据库连接对象
                Statement st=conn.createStatement();
                //创建SQL语句执行对象
                String  strSQL1="update dbo.huiyuan set 姓名='"+updateName+"' where 姓名='"+Name+"'";
                String  strSQL2="update dbo.huiyuan set 性别='"+sex+"' where 姓名='"+Name+"'";
                String  strSQL3="update dbo.huiyuan set 年龄='"+age+"' where 姓名='"+Name+"'";
                String  strSQL4="update dbo.huiyuan set 联系方式='"+number+"' where 姓名='"+Name+"'";
                String  strSQL5="update dbo.huiyuan set 会员编号='"+id+"' where 姓名='"+Name+"'";

                int rs1=st.executeUpdate(strSQL1);
                int rs2=st.executeUpdate(strSQL2);
                int rs3=st.executeUpdate(strSQL3);
                int rs4=st.executeUpdate(strSQL4);
                int rs5=st.executeUpdate(strSQL5);
                if(rs1==1||rs2==1||rs3==1||rs4==1||rs5==1) {
                    JOptionPane.showMessageDialog(null,"修改成功");
                }
                else{
                    JOptionPane.showMessageDialog(null,"修改失败");
                }
                conn.close();

                //关闭数据库连接
            }
            catch (ClassNotFoundException ex) {
                System.out.println("没有找到对应的数据库驱动类");
            }
            catch (SQLException ex) {
                System.out.println("数据库连接或者是数据库操作失败");
            }

        }
    });

}

public void win6(){
    win6.setLayout(null);
    win6.setVisible(true);
    win6.setBounds(500,500,600,400);

    JLabel lab1= new JLabel("姓名");

    JTextField jtex1= new JTextField();


    lab1.setSize(50,30);
    lab1.setLocation(100,70);

    win6.add(lab1);

    jtex1.setSize(80,30);
    jtex1.setLocation(180,70);

    win6.add(jtex1);

    JButton bt1=new JButton("点击删除");
    JButton bt2=new JButton("点击返回");

    bt1.setSize(100,50);
    bt1.setLocation(400,100);
    bt2.setSize(100,50);
    bt2.setLocation(400,200);

    win6.add(bt1);
    win6.add(bt2);
    bt2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win6.setVisible(false);
            win2();
        }
    });
    bt1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String delName=jtex1.getText();
            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                //加载对应的jdbc驱动
                String url="jdbc:sqlserver://localhost:1433; DatabaseName=supermaket";
                //配置连接字符串
                String user="sa";//sa超级管理员
                String password="123";//密码
                Connection conn=DriverManager.getConnection(url,user,password);
                //创建数据库连接对象
                Statement st=conn.createStatement();
                //创建SQL语句执行对象
                String strSQL="delete from  dbo.huiyuan where 姓名='"+delName+"' ";

                int rs=st.executeUpdate(strSQL);
                if(rs==1) {
                    JOptionPane.showMessageDialog(null,"删除成功");
                }
                else{
                    JOptionPane.showMessageDialog(null,"删除失败");
                }
                conn.close();

                //关闭数据库连接
            }
            catch (ClassNotFoundException ex) {
                System.out.println("没有找到对应的数据库驱动类");
            }
            catch (SQLException ex) {
                System.out.println("数据库连接或者是数据库操作失败");
            }
        }
    });

}
public void win7(){
    win7.setLayout(null);
    win7.setVisible(true);
    win7.setBounds(500,500,600,400);

    JLabel lab1= new JLabel("姓名");
    JLabel lab2= new JLabel("性别");
    JLabel lab3= new JLabel("年龄");
    JLabel lab4= new JLabel("联系方式");
    JLabel lab5= new JLabel("编号");


    JTextField jtex1= new JTextField();
    JTextField jtex2= new JTextField();
    JTextField jtex3= new JTextField();
    JTextField jtex4= new JTextField();
    JTextField jtex5= new JTextField();

    lab1.setSize(80,30);
    lab1.setLocation(100,70);

    lab2.setSize(80,30);
    lab2.setLocation(100,120);

    lab3.setSize(80,30);
    lab3.setLocation(100,170);

    lab4.setSize(80,30);
    lab4.setLocation(100,220);


    lab5.setSize(80,30);
    lab5.setLocation(100,270);

    win7.add(lab1);
    win7.add(lab2);
    win7.add(lab3);
    win7.add(lab4);
    win7.add(lab5);

    jtex1.setSize(80,30);
    jtex1.setLocation(180,70);

    jtex2.setSize(80,30);
    jtex2.setLocation(180,120);

    jtex3.setSize(80,30);
    jtex3.setLocation(180,170);

    jtex4.setSize(80,30);
    jtex4.setLocation(180,220);

    jtex5.setSize(80,30);
    jtex5.setLocation(180,270);

    win7.add(jtex1);
    win7.add(jtex2);
    win7.add(jtex3);
    win7.add(jtex4);
    win7.add(jtex5);

    JButton bt1=new JButton("点击添加");
    JButton bt2=new JButton("点击返回");

    bt1.setSize(100,50);
    bt1.setLocation(400,100);
    bt2.setSize(100,50);
    bt2.setLocation(400,200);

    win7.add(bt1);
    win7.add(bt2);

    bt2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win7.setVisible(false);
            win2();
        }
    });

    bt1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String addName=jtex1.getText();
            String addsex=jtex2.getText();
            String addage=jtex3.getText();
            String addnumber=jtex4.getText();
            String addid=jtex5.getText();

            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                //加载对应的jdbc驱动
                String url="jdbc:sqlserver://localhost:1433; DatabaseName= supermaket";
                //配置连接字符串
                String user="sa";//sa超级管理员
                String password="123";//密码
                Connection conn=DriverManager.getConnection(url,user,password);
                //创建数据库连接对象
                Statement st=conn.createStatement();
                //创建SQL语句执行对象

                String  strSQL="insert into  dbo.huiyuan values('"+addName+"','"+addsex+"','"+addage+"','"+addnumber+"','"+addid+"')";

                int rs=st.executeUpdate(strSQL);
                if(rs==1) {
                    JOptionPane.showMessageDialog(null,"添加成功");
                }
                else{
                    JOptionPane.showMessageDialog(null,"添加失败");
                }
                conn.close();

                //关闭数据库连接
            }
            catch (ClassNotFoundException ex) {
                System.out.println("没有找到对应的数据库驱动类");
            }
            catch (SQLException ex) {
                System.out.println("数据库连接或者是数据库操作失败");
            }
        }

    });
}
public void win8(){
    win8.setLayout(null);
    win8.setVisible(true);
    win8.setBounds(500,500,600,400);


    JLabel lab1= new JLabel("需要查找的姓名");
    JLabel lab2= new JLabel("姓名");
    JLabel lab3= new JLabel("性别");
    JLabel lab4= new JLabel("年龄");
    JLabel lab5= new JLabel("联系方式");
    JLabel lab6= new JLabel("会员编号");

    JTextField jtex1= new JTextField();
    JTextField jtex2= new JTextField();
    JTextField jtex3= new JTextField();
    JTextField jtex4= new JTextField();
    JTextField jtex5= new JTextField();
    JTextField jtex6= new JTextField();


    lab1.setSize(80,30);
    lab1.setLocation(100,20);

    lab2.setSize(80,30);
    lab2.setLocation(100,70);

    lab3.setSize(80,30);
    lab3.setLocation(100,120);

    lab4.setSize(80,30);
    lab4.setLocation(100,170);


    lab5.setSize(80,30);
    lab5.setLocation(100,220);

    lab6.setSize(80,30);
    lab6.setLocation(100,270);


    win8.add(lab1);
    win8.add(lab2);
    win8.add(lab3);
    win8.add(lab4);
    win8.add(lab5);
    win8.add(lab6);

    jtex1.setSize(80,30);
    jtex1.setLocation(180,20);

    jtex2.setSize(80,30);
    jtex2.setLocation(180,70);

    jtex3.setSize(80,30);
    jtex3.setLocation(180,120);

    jtex4.setSize(80,30);
    jtex4.setLocation(180,170);

    jtex5.setSize(80,30);
    jtex5.setLocation(180,220);

    jtex6.setSize(80,30);
    jtex6.setLocation(180,270);

    win8.add(jtex1);
    win8.add(jtex2);
    win8.add(jtex3);
    win8.add(jtex4);
    win8.add(jtex5);
    win8.add(jtex6);

    JButton bt1=new JButton("点击查找");
    JButton bt2=new JButton("点击返回");

    bt1.setSize(100,50);
    bt1.setLocation(400,100);
    bt2.setSize(100,50);
    bt2.setLocation(400,200);

    win8.add(bt1);
    win8.add(bt2);

    bt2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win8.setVisible(false);
            win2();
        }
    });
    bt1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String inputName=jtex1.getText();

            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                //加载对应的jdbc驱动
                String url="jdbc:sqlserver://localhost:1433; DatabaseName=supermaket";
                //配置连接字符串
                String user="sa";//sa超级管理员
                String password="123";//密码
                Connection conn=DriverManager.getConnection(url,user,password);
                //创建数据库连接对象
                Statement st=conn.createStatement();
                //创建SQL语句执行对象

                String  strSQL="(Select* from  dbo.huiyuan where 姓名='"+inputName+"' )";
                ResultSet rs=st.executeQuery(strSQL);

                if(rs.next())
                {
                    jtex2.setText(rs.getString(1));
                    jtex3.setText(rs.getString(2));
                    jtex4.setText(rs.getString(3));
                    jtex5.setText(rs.getString(4));
                    jtex6.setText(rs.getString(5));

                }
                else
                {
                    JOptionPane.showMessageDialog(null, "您查询的数据不存在,请重新输入");
                }
                conn.close();

                //关闭数据库连接
            }
            catch (ClassNotFoundException ex) {
                System.out.println("没有找到对应的数据库驱动类");
            }
            catch (SQLException ex) {
                System.out.println("数据库连接或者是数据库操作失败");
            }



        }
    });
}
public void win9(){

    win9.setLayout(null);
    win9.setVisible(true);
    win9.setBounds(500,500,600,400);

    JButton bt1=new JButton("查询");
    JButton bt2=new JButton("添加");
    JButton bt3=new JButton("修改");
    JButton bt4=new JButton("删除");
    JButton bt5=new JButton("返回");

    bt1.setSize(80,40);
    bt1.setLocation(10,300);
    bt2.setSize(80,40);
    bt2.setLocation(110,300);
    bt3.setSize(80,40);
    bt3.setLocation(210,300);
    bt4.setSize(80,40);
    bt4.setLocation(310,300);
    bt5.setSize(80,40);
    bt5.setLocation(410,300);

    win9.add(bt1);
    win9.add(bt2);
    win9.add(bt3);
    win9.add(bt4);
    win9.add(bt5);

    bt1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win9.setVisible(false);
            win10();
        }
    });

    bt2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win9.setVisible(false);
            win11();
        }
    });

    bt3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win9.setVisible(false);
            win12();
        }
    });

    bt4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win9.setVisible(false);
            win13();
        }
    });

    bt5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win9.setVisible(false);
            win1();
        }
    });


}
public void win10(){
    win10.setLayout(null);
    win10.setVisible(true);
    win10.setBounds(500,500,600,400);

    JLabel lab1= new JLabel("需找编号");
    JLabel lab2= new JLabel("编号");
    JLabel lab3= new JLabel("积分");
    JLabel lab4= new JLabel("优惠政策");

    JTextField jtex1= new JTextField();
    JTextField jtex2= new JTextField();
    JTextField jtex3= new JTextField();
    JTextField jtex4= new JTextField();

    lab1.setSize(80,30);
    lab1.setLocation(100,20);

    lab2.setSize(80,30);
    lab2.setLocation(100,70);

    lab3.setSize(80,30);
    lab3.setLocation(100,120);

    lab4.setSize(80,30);
    lab4.setLocation(100,170);

    win10.add(lab1);
    win10.add(lab2);
    win10.add(lab3);
    win10.add(lab4);

    jtex1.setSize(80,30);
    jtex1.setLocation(180,20);

    jtex2.setSize(80,30);
    jtex2.setLocation(180,70);

    jtex3.setSize(80,30);
    jtex3.setLocation(180,120);

    jtex4.setSize(80,30);
    jtex4.setLocation(180,170);

    win10.add(jtex1);
    win10.add(jtex2);
    win10.add(jtex3);
    win10.add(jtex4);

    JButton bt1=new JButton("点击查找");
    JButton bt2=new JButton("点击返回");

    bt1.setSize(100,50);
    bt1.setLocation(400,100);
    bt2.setSize(100,50);
    bt2.setLocation(400,200);

    win10.add(bt1);
    win10.add(bt2);

    bt2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win10.setVisible(false);
            win9();
        }
    });
    bt1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String inputName=jtex1.getText();

            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                //加载对应的jdbc驱动
                String url="jdbc:sqlserver://localhost:1433; DatabaseName=supermaket";
                //配置连接字符串
                String user="sa";//sa超级管理员
                String password="123";//密码
                Connection conn=DriverManager.getConnection(url,user,password);
                //创建数据库连接对象
                Statement st=conn.createStatement();
                //创建SQL语句执行对象

                String  strSQL="(Select* from  dbo.youhui where 会员编号='"+inputName+"' )";
                ResultSet rs=st.executeQuery(strSQL);

                if(rs.next())
                {
                    jtex2.setText(rs.getString(1));
                    jtex3.setText(rs.getString(2));
                    jtex4.setText(rs.getString(3));
                }
                else
                {
                    JOptionPane.showMessageDialog(null, "您查询的数据不存在,请重新输入");
                }
                conn.close();

                //关闭数据库连接
            }
            catch (ClassNotFoundException ex) {
                System.out.println("没有找到对应的数据库驱动类");
            }
            catch (SQLException ex) {
                System.out.println("数据库连接或者是数据库操作失败");
            }



        }
    });

}
public void win11(){
    win11.setLayout(null);
    win11.setVisible(true);
    win11.setBounds(500,500,600,400);

    JLabel lab1= new JLabel("会员编号");
    JLabel lab2= new JLabel("会员积分");
    JLabel lab3= new JLabel("优惠政策");

    JTextField jtex1= new JTextField();
    JTextField jtex2= new JTextField();
    JTextField jtex3= new JTextField();

    lab1.setSize(80,30);
    lab1.setLocation(100,20);

    lab2.setSize(80,30);
    lab2.setLocation(100,70);

    lab3.setSize(80,30);
    lab3.setLocation(100,120);

    win11.add(lab1);
    win11.add(lab2);
    win11.add(lab3);

    jtex1.setSize(80,30);
    jtex1.setLocation(180,20);

    jtex2.setSize(80,30);
    jtex2.setLocation(180,70);

    jtex3.setSize(80,30);
    jtex3.setLocation(180,120);

    win11.add(jtex1);
    win11.add(jtex2);
    win11.add(jtex3);

    JButton bt1=new JButton("点击添加");
    JButton bt2=new JButton("点击返回");

    bt1.setSize(100,50);
    bt1.setLocation(400,100);
    bt2.setSize(100,50);
    bt2.setLocation(400,200);

    win11.add(bt1);
    win11.add(bt2);

    bt2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win11.setVisible(false);
            win9();
        }
    });

    bt1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String addid=jtex1.getText();
            String addnumber=jtex2.getText();
            String add=jtex3.getText();

            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                //加载对应的jdbc驱动
                String url="jdbc:sqlserver://localhost:1433; DatabaseName= supermaket";
                //配置连接字符串
                String user="sa";//sa超级管理员
                String password="123";//密码
                Connection conn=DriverManager.getConnection(url,user,password);
                //创建数据库连接对象
                Statement st=conn.createStatement();
                //创建SQL语句执行对象

                String  strSQL="insert into  dbo.youhui values('"+addid+"','"+addnumber+"','"+add+"' )";

                int rs=st.executeUpdate(strSQL);
                if(rs==1) {
                    JOptionPane.showMessageDialog(null,"添加成功");
                }
                else{
                    JOptionPane.showMessageDialog(null,"添加失败");
                }
                conn.close();

                //关闭数据库连接
            }
            catch (ClassNotFoundException ex) {
                System.out.println("没有找到对应的数据库驱动类");
            }
            catch (SQLException ex) {
                System.out.println("数据库连接或者是数据库操作失败");
            }
        }

    });

}

public void win12(){
    win12.setLayout(null);
    win12.setVisible(true);
    win12.setBounds(500,500,600,400);

    JLabel lab1= new JLabel("需改编号");
    JLabel lab2= new JLabel("会员编号");
    JLabel lab3= new JLabel("会员积分");
    JLabel lab4= new JLabel("折扣");

    JTextField jtex1= new JTextField();
    JTextField jtex2= new JTextField();
    JTextField jtex3= new JTextField();
    JTextField jtex4= new JTextField();

    lab1.setSize(80,30);
    lab1.setLocation(100,70);

    lab2.setSize(80,30);
    lab2.setLocation(100,120);

    lab3.setSize(80,30);
    lab3.setLocation(100,170);

    lab4.setSize(80,30);
    lab4.setLocation(100,220);

    win12.add(lab1);
    win12.add(lab2);
    win12.add(lab3);
    win12.add(lab4);

    jtex1.setSize(80,30);
    jtex1.setLocation(180,70);

    jtex2.setSize(80,30);
    jtex2.setLocation(180,120);

    jtex3.setSize(80,30);
    jtex3.setLocation(180,170);

    jtex4.setSize(80,30);
    jtex4.setLocation(180,220);

    win12.add(jtex1);
    win12.add(jtex2);
    win12.add(jtex3);
    win12.add(jtex4);

    JButton bt1=new JButton("点击修改");
    JButton bt2=new JButton("点击返回");

    bt1.setSize(100,50);
    bt1.setLocation(400,100);
    bt2.setSize(100,50);
    bt2.setLocation(400,200);

    win12.add(bt1);
    win12.add(bt2);

    bt2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win12.setVisible(false);
            win9();
        }
    });

    bt1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String id=jtex1.getText();
            String updateid=jtex2.getText();
            String updatenumber=jtex3.getText();
            String update=jtex4.getText();

            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                //加载对应的jdbc驱动
                String url="jdbc:sqlserver://localhost:1433; DatabaseName=supermaket";
                //配置连接字符串
                String user="sa";//sa超级管理员
                String password="123";//密码
                Connection conn=DriverManager.getConnection(url,user,password);
                //创建数据库连接对象
                Statement st=conn.createStatement();
                //创建SQL语句执行对象
                String  strSQL1="update dbo.youhui set 会员编号='"+updateid+"' where 会员编号='"+id+"'";
                String  strSQL2="update dbo.youhui set 会员积分='"+updatenumber+"' where 会员编号='"+id+"'";
                String  strSQL3="update dbo.youhui set 优惠政策='"+update+"' where 会员编号='"+id+"'";

                int rs1=st.executeUpdate(strSQL1);
                int rs2=st.executeUpdate(strSQL2);
                int rs3=st.executeUpdate(strSQL3);

                if(rs1==1||rs2==1||rs3==1) {
                    JOptionPane.showMessageDialog(null,"修改成功");
                }
                else{
                    JOptionPane.showMessageDialog(null,"修改失败");
                }
                conn.close();

                //关闭数据库连接
            }
            catch (ClassNotFoundException ex) {
                System.out.println("没有找到对应的数据库驱动类");
            }
            catch (SQLException ex) {
                System.out.println("数据库连接或者是数据库操作失败");
            }

        }
    });

}

public void win13(){
    win13.setLayout(null);
    win13.setVisible(true);
    win13.setBounds(500,500,600,400);

    JLabel lab1= new JLabel("会员编号");

    JTextField jtex1= new JTextField();

    lab1.setSize(50,30);
    lab1.setLocation(100,70);

    win13.add(lab1);

    jtex1.setSize(80,30);
    jtex1.setLocation(180,70);

    win13.add(jtex1);

    JButton bt1=new JButton("点击删除");
    JButton bt2=new JButton("点击返回");

    bt1.setSize(100,50);
    bt1.setLocation(400,100);
    bt2.setSize(100,50);
    bt2.setLocation(400,200);

    win13.add(bt1);
    win13.add(bt2);
    bt2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            win13.setVisible(false);
            win9();
        }
    });
    bt1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String delid=jtex1.getText();
            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                //加载对应的jdbc驱动
                String url="jdbc:sqlserver://localhost:1433; DatabaseName=supermaket";
                //配置连接字符串
                String user="sa";//sa超级管理员
                String password="123";//密码
                Connection conn=DriverManager.getConnection(url,user,password);
                //创建数据库连接对象
                Statement st=conn.createStatement();
                //创建SQL语句执行对象
                String strSQL="delete from  dbo.youhui where 会员编号='"+delid+"' ";

                int rs=st.executeUpdate(strSQL);
                if(rs==1) {
                    JOptionPane.showMessageDialog(null,"删除成功");
                }
                else{
                    JOptionPane.showMessageDialog(null,"删除失败");
                }
                conn.close();

                //关闭数据库连接
            }
            catch (ClassNotFoundException ex) {
                System.out.println("没有找到对应的数据库驱动类");
            }
            catch (SQLException ex) {
                System.out.println("数据库连接或者是数据库操作失败");
            }
        }
    });
}


    public static void main(String[] args) {
        caidan caidan=new caidan();
        caidan.win1();;
    }
}

  • 19
    点赞
  • 89
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 20
    评论
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mikeyuyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值