10.31

发布时间 2023-12-16 23:32:44作者: 张佳木

今日学习内容

<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.*" %><%--
Created by IntelliJ IDEA.
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
int cid= Integer.parseInt(request.getParameter("cid"));
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
request.setCharacterEncoding("utf-8");
Connection conn = null;
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/2017xuanke", "root", "123456");
Statement stat = null;
String sql = "delete from course where cid = "+cid;
stat = conn.createStatement();
int i=stat.executeUpdate(sql);
if(i!=0){
System.out.println("成功删除");}
else{
System.out.println("删除失败");

}
stat.close();
conn.close();
%>

</body>
</html>