javaweb中servlet删除出现红

javaweb中servlet删除出现红,实现对数据库信息的删除

img

你这是用类名调用的update,这个方法是非静态的,你需要用实例对象才行
另外update是更新吧,你是删除语句,删除语句 where后面 缺少条件字段

调用非静态的update方法

import org.apache.commons.dbutils.QueryRunner;

public class YourServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 创建QueryRunner实例
        QueryRunner queryRunner = new QueryRunner();

        // 调用非静态的update方法
        try {
            int result = queryRunner.update("DELETE FROM your_table WHERE id = ?", yourId);
            // 处理结果
        } catch (SQLException e) {
            e.printStackTrace();
            // 处理异常
        }
    }
}


直接类名.方法名,那你这个方法需要是static修饰的静态方法,sql语句也不对 delete from t_user where id=?

img

报错说的是update方法不是静态方法所以不能这么用,
你前面已经有queryRunner这个对象,将他改成queryRunner.update试试