哈喽,大家好,我是你们可爱的小编,今天,带来了新闻系统的后续,今天就分享增删改查的功能吧!
一,删除功能的实现
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.Connection" %>
<%
//删除没有界面del,只有doDel后台,在read界面点击删除按钮就会执行这个后台
//获得新闻的id,根据id去数据库做删除操作
String newId = request.getParameter("newId");
//加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//定义连接字符串
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
//获得连接
Connection con = DriverManager.getConnection(url, "scott", "123");
//查询所有的新闻数据
PreparedStatement ps = con.prepareStatement("delete from t1_news where news_id=?");
//占位符的设置
ps.setInt(1,Integer.parseInt(newId));
//执行并获得结果 【收到影响的行数】
int i = ps.executeUpdate();
if(i>0){
//删除成功
out.print("<script>alert('删除成功');location.href='index.jsp'</script>");
}else{
//删除失败
//history.go(-1)跳到上一页即doDel
out.print("<script>alert('删除失败');history.go(-1)</script>");
}
%>
二,修改的界面及功能
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Connection" %>
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>bootstrap</title>
<meta content="width=device-width, initial-scale=1" name="viewport">
<link href="${pageContext.request.contextPath}/bootstrap-3.3.7-dist/css/bootstrap.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/bootstrap-3.3.7-dist/js/jquery-3.5.1.js"></script>
<script src="${pageContext.request.contextPath}/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
<style>
* {
outline: none !important;
}
body,
html {
background: #7f8d90;
}
nav,
.breadcrumb {
border-radius: 0 !important;
margin-bottom: 0 !important;
}
.breadcrumb {
margin-bottom: 20px !important;
background: #36485c;
color: white;
}
input,
select,
textarea,
.panel-heading {
border: none !important;
border-radius: 0 !important;
}
.breadcrumb .active {
color: yellow;
}
</style>
</head>
<body>
<nav class="navbar navbar-default hidden-sm hidden-xs">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="${pageContext.request.contextPath}/news/index.jsp"
style="font-size: 25px;">🐖🐖🐖🐖</a>
</div>
<ul class="nav navbar-nav">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown">
新闻管理
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="#">新闻发布</a></li>
<li class="divider"></li>
<li><a href="#">类别管理</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a>245@qq.com</a><