如何使用JDBC删除一条记录

//根据学生id删除操作
    public void deleteOne(int id) {
        Statement stmt=null;     //  发送SQL语句,返回执行结果
        try {
            
            strSql="delete from student where id= "+id;   //删除的SQL语句
            stmt=conn.createStatement();   //连接数据库,提交SQL语句
            //执行SQL
            stmt.executeUpdate(strSql);
            System.out.println("删除数据成功"+strSql);
            
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }

猜你喜欢

转载自www.cnblogs.com/TangGe520/p/8940030.html