⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 delcategory.jsp

📁 大学JSP课程大作业
💻 JSP
字号:
<%@ page contentType="text/html; charset=gb2312"%>

<%@ page import="java.sql.*" %>
<%@ page import="my.shop.db.*" %>

<%-- 会话过滤 --%>
<%@ include file="sessionfilter.jsp" %>

<%
	String id = request.getParameter("id") ;
	Connection conn = DBConnection.getInstance().getConnection() ;
	//conn.setAutoCommit(false) ;
	//删除类别要把所有本类别下的产品也删除,保证数据完整性
	String getFilename = "select picture from product where cateid='"+ id+"'" ;
	Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE) ;
	ResultSet rsfilename = stmt.executeQuery(getFilename) ;
	rsfilename.last() ;
	String filename[] = new String[rsfilename.getRow()] ;
	rsfilename.beforeFirst() ;
	int i = 0 ;
	while(rsfilename.next()){
		filename[i] = rsfilename.getString(1) ;
		i++ ;
	}
	for(int j=0; j<filename.length; j++){
		java.io.File delFile = new java.io.File(getServletContext().getRealPath("/")+"productimage\\"+filename[j]); //取得指定路径下的指定文件
		if(delFile.exists() && delFile.isFile()){//删除指定的磁盘文件
			delFile.delete();
		}
	}
	String delproductsql = "delete from product where cateid=?" ;
	PreparedStatement pstmt = conn.prepareStatement(delproductsql) ;
	pstmt.setString(1,id) ;
	pstmt.executeUpdate() ;
	pstmt.close() ;
	//删除类别
	String delcatesql = "delete from category where id=?" ;
	
	pstmt = conn.prepareStatement(delcatesql) ;
	pstmt.setString(1,id) ;
	pstmt.executeUpdate() ;
	out.println("<div align='center'><font color=blue>指定类别成功删除!</font></div><br><a href='mgrcategory.jsp'>返回</a>") ;
	//conn.commit() ;
	rsfilename.close() ;
	stmt.close() ;
	pstmt.close() ;
	conn.close() ;
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -