JDBC连接数据库进行数据删除,语法正确,但是数据库里面的数据不能删除

JDBC连接数据库进行数据删除,语法正确,但是数据库里面的数据不能删除

问题描述:

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
public void del_stu() {
        JFrame jf = new JFrame("宿舍信息删除------>");
        JLabel jl1 = new JLabel("学生姓名:");
        JTextField jt1 = new JTextField("",10);
        JLabel jl2 = new JLabel("学生学号:");
        JTextField jt2 = new JTextField("",15);
        JButton jb1 = new JButton("删除");
        jf.setLayout(new FlowLayout(FlowLayout.CENTER));
        String stuname = jt1.getText();
        String stuid = jt2.getText();
        jb1.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    Class.forName("com.mysql.cj.jdbc.Driver");//加载mysql驱动
                    String URL = "jdbc:mysql://localhost:3306/dor_information?&useSSL=false&serverTimezone=UTC&serverTimezone=GMT%2B8";
                    Connection connection = Connect.getConnection();
                    Statement statement = connection.createStatement();
                    String sql = "delete from dor_stu where 学号 =? ";
                    PreparedStatement pstmt = connection.prepareStatement(sql);
                    pstmt.setString(1, stuid);
                    pstmt.executeUpdate();
                    ResultSet rs = statement.executeQuery("select *from dor_stu");
                    while(rs.next()) {
                        if(!rs.getString(2).equals(stuid)) {
                            System.out.println("删除成功");
                        }
                    }
                }catch(Exception e1) {
                    e1.printStackTrace();
                }
            }
        });

运行结果及报错内容

这里报的是删除成功

我的解答思路和尝试过的方法
我想要达到的结果

数据库能够删除该数据就可以了

1.

执行删除的sql后需要commit 提交事务