81,092
社区成员
发帖
与我相关
我的任务
分享
<%
/*
当你点删除时候连接到下个页面同时把要删除的id传到下个页面
<th width="10%" valign="middle"><a href="deletesucess.jsp?id=<%=id%>">删除</a></th>
</tr>
*/
int pid;
pid=Integer.parseInt(request.getParameter("id").trim());
System.out.println(pid);
//jdbc连接数据库
Connection con =null;
Statement str = null;
try{
String url="jdbc:odbc:数据源名";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection(url,"","");
String sql = "delete from 表名 where id = '" + pid + "'";
str=con.createStatement();
str.executeUpdate(sql);
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e1){
e1.printStackTrace();
}finally{
try{
if(str!=null){
str.close();
str=null;
}
if(con!=null){
con.close();
con=null;
}
}catch(Exception e){
e.printStackTrace();
}
}
%>
<%
String id = request.getParameter("id");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(ClassNotFoundException ce){
out.println(ce.getMessage());
}
try{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db";
String user="db";
String password="db";
conn= DriverManager.getConnection(url,user,password);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
int iBack =stmt.executeUpdate("delete from table where id='"+id+"' ");
out.println("<SCRIPT language=JavaScript>alert('操作成功);javascript:history.go(-1);</script>");
}
catch(SQLException e){
System.out.println(e.getMessage());
}
finally{
stmt.close();
conn.close();
}
%>
"delete from zhuce where id='"+id