---
title: "删除传来的相应用户ID"
author: "ningzai"
date: "2008-12-17T01:46:59Z"
tags: []
slug: "id"
draft: false
lastmod: "2008-12-17T01:46:59Z"
id: 295695
url: "https://ningzai.iteye.com/blog/295695"
---

<%//接受用户ID
 long id;
 try{
  id=Long.parseLong(request.getParameter("id"));
   }catch (Exception e)
   {
    id=0;
   }
 %>
 <%//构造删除记录SQL语句
 String sqlString=null;
 if(id!=0){
  sqlString="delete from usertable where id="+id;
    try{
    Connection con;
    Statement sql;
    Class.forName("com.mysql.jdbc.Driver");//加载数据库驱动程序；
    con=DriverManager.getConnection("jdbc:mysql://localhost:3306/jsp","root","7056503");
     sql=con.createStatement();
     sql.executeUpdate(sqlString);
     con.close();
     
    }
    catch(SQLException e){
     out.print("SQL异常！");
    }
 }
 
  %>