?? delete.jsp
字號:
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*"%>
<%
String strlog = (String)session.getAttribute("admin");
if(strlog == null || !strlog.equals("true")){
out.println("<center>對不起請先登錄"+"<br><a href=Login.jsp>管理員登錄</a></center>");
return;
}
%>
<%!
private void del(Connection conn,int id){
Statement st = null;
ResultSet rs = null;
try{
st = conn.createStatement();
String sql = "select * from article where pid = " + id;
rs = st.executeQuery(sql);
while(rs.next()) {
del(conn, rs.getInt("id"));
}
st.executeUpdate("delete from article where id=" + id);
}catch(SQLException e){
System.out.println("系統(tǒng)找不到指定數(shù)據(jù)庫");
}
try{
if(rs != null){
rs.close();
rs = null;
}
if(st != null){
st.close();
st = null;
}
}catch(SQLException e){
System.out.println("數(shù)據(jù)庫已經(jīng)關(guān)閉");
}
}
%>
<%
int id = Integer.parseInt(request.getParameter("id"));
int pid = Integer.parseInt(request.getParameter("pid"));
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mySQL://localhost/bbs?user=root&password=yuanshuai");
Statement st = conn.createStatement();
conn.setAutoCommit(false);
del(conn,id);
ResultSet rs = st.executeQuery("select count(*) from article where id=" + pid);
rs.next();
int count = rs.getInt(1);
if(count <= 0){
st.executeUpdate("update article set isleaf=0 where id=" + pid);
}
conn.commit();
conn.setAutoCommit(true);
try{
if(st != null){
st.close();
st = null;
}
if(conn != null){
conn.close();
conn = null;
}
}catch(SQLException e){
System.out.println("數(shù)據(jù)庫已經(jīng)關(guān)閉");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>刪除頁面</title>
</head>
<body>
<div align="center">
<font size=6 color="red"><br>恭喜你!</font><br><br>
<font size=6 color="red">內(nèi)容已經(jīng)成功刪除</font><br><br>
<a href="ShowArticalTree.jsp">返回</a>
</div>
</body>
</html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -