示例代码如下:

 Connection con = null; //定义一个MYSQL链接对象
                    Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动
                    con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/blog", "root", "123456"); //链接本地MYSQL

                    Statement stmt; //创建声明
                    stmt = con.createStatement();

                    //update 
                  
                
                   String sql = "Update user Set views='"+b+"' Where cid='"+a+"'";

                    stmt.executeUpdate(sql);//执行sql语句
                    JOptionPane.showConfirmDialog(null, "恭喜!数据写入成功!", "温馨提示", JOptionPane.YES_NO_OPTION); 
                    con.close();
                   
                   

                } catch (Exception e) {
                    System.out.print("MYSQL ERROR:" + e.getMessage());
                }

更新命令

Update 表名 Set 字段='"字段值"' Where id='"id"值'";

最后修改:2023 年 08 月 04 日
如果觉得我的文章对你有用,请随意赞赏