java选中table中的某一个值右键弹出修改窗口,修改后数据为什么没有变

相关代码
public void mouseClicked(MouseEvent mouseEvent) {
                                    if (mouseEvent.getButton() == MouseEvent.BUTTON3){
                                        //得到选中的行列的索引值
                                        int r= table1.getSelectedRow();
                                        int c= table1.getSelectedColumn();
                                        //得到选中的单元格的值,表格中都是字符串
                                        Object value= table1.getValueAt(r, c);
                                        String info="确认要修改"+r+"行"+c+"列的数据 : "+value.toString()+" 吗?";
                                        int k = JOptionPane.showConfirmDialog(null, info, "修改", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                                        //获取数据库中的列名
                                        String[] colnames = goodService.getcolumn();
                                        String colname = null;
                                        for (int i = 0; i < colnames.length; i ++){
                                            if (c == i){
                                                //判断table中某一列与数据库中表的某一列是否相同
                                                colname = colnames[i];
                                            }
                                        }
                                        if (k == JOptionPane.YES_OPTION){
                                            Object strin = JOptionPane.showInputDialog(null, "请输入要修改的数据:");
                                            //获取选中行的id
                                            String id = table1.getValueAt(r, 0).toString();
                                            System.out.println(strin + id);
                                            System.out.println(colname);
                                            String sql = "update Goods set ?=? where id=?";
                                            DBUtil db = new DBUtil();
                                            try {
                                                db.getConnection();
                                                int count = db.executeUpdate(sql, new Object[]{colname, strin, id});
                                                if (count > 0){
                                                    JOptionPane.showMessageDialog(null, "修改成功", "成功", JOptionPane.PLAIN_MESSAGE);
                                                    String sqlsel = "select id as 商品编号, name as 商品名称, input as 商品进价, output as 商品售价, number as 商品数量 from Goods";
                                                    //重新读取数据库中的数据
                                                    readGoodsResult(sqlsel, null);
                                                }else {
                                                    JOptionPane.showMessageDialog(null, "修改失败", "失败", 0);
                                                }
                                            }catch (Exception e){
                                                JOptionPane.showMessageDialog(null, "系统错误", "失败", 0);
                                                e.printStackTrace();
                                                db.closeAll();
                                            }
                                        }
                                    }
                            }

//获取数据表列名
    public String[] getcolumn() {
        String[] colname = null;
        DBUtil db = new DBUtil();
        try {
            db.getConnection();
            ResultSet rs = db.executeQuery("SELECT * FROM Goods", null);
            ResultSetMetaData rsmd = rs.getMetaData();
            int count = rsmd.getColumnCount();
            String[] col = new String[count];
            for (int i = 0; i < count; i++) {
                col[i] = rsmd.getColumnName(i + 1);
            }
            colname = col;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            db.closeAll();
        }
        return colname;
    }

public int executeUpdate(String preparedSql, Object[] param) {
        int num = 0;
        try {
            pstmt = conn.prepareStatement(preparedSql);
            if (param != null) {
                for (int i = 0; i < param.length; i++) {
                    // 为预编译sql设置参数
                    pstmt.setObject(i + 1, param[i]);
                }
            }else {
                throw new RuntimeException("Object[] param的数组长度,不应该为空");
            }
            //执行SQL语句
            num = pstmt.executeUpdate();
        } catch (SQLException e) {
            throw new RuntimeException("更新数据库中的记录失败" + e);
        }
        return num;
    }

//数据库的表
create table Goods
(
    id     nvarchar(6) not null
        constraint table_name_pk
            primary key nonclustered,
    name   nvarchar(8) not null,
    input  int         not null,
    output int         not null,
    number int         not null
)
go

######代码感觉也没有问题

img

img

img

显示修改成功,但是数据库和表格中的数据都没有变

打断点看