1

我试图在这里使用 jsp 更新列我希望我的计数列值更新为零计数 = 0 我该怎么做。通过此代码值未更新

   String code = request.getParameter("code");
   Connection conn = null;
   Statement st=null;
   ResultSet rs = null;
   PreparedStatement ps = null;
   int count = 0;

   try{
     conn = DataBaseConnection.initializeDatabase();
     


    String query1 = null;
     conn.setAutoCommit(false);
     query1 = "update employee set count = ? where code= ' +code+' ";
        ps = conn.prepareStatement(query1);
        ps.setInt(1, count);
        ps.executeUpdate();
        }
        catch (Exception e) {
        e.printStackTrace();
        }

这是我在 db 员工表 CODE VARCHAR2(12) COUNT NUMBER(3) 中的记录

4

1 回答 1

1

你可以更换

"update employee set count = ? where code= ' +code+' ";

"update employee set count = ? where code= '" + code + "'";

例如,如果 code 的值xyz在此更改之后,则查询将变为:

"update employee set count = ? where code= 'xyz'";

但是,我建议您执行以下操作以避免SQL 注入

query1 = "update employee set count = ? where code= ?";
ps = conn.prepareStatement(query1);
ps.setInt(1, count);
ps.setString(2, code);
于 2020-10-06T06:04:44.190 回答