JavaWeb数据库学生宿舍图书管理系统+地图
- 登陆之后现实主页面,账号密码储存在数据库中。
- 实现对数据库的增删改查
java 9.0.4 + mysql 8.0.19 + Navicat 8 lite + eclipse 2019-12 + mysql-connector-java-8.0.19.jar
环境搭建:
[wxcaptcha]链接:https://pan.baidu.com/s/1HBIwaRJZuOc2d7ut8KpStQ
提取码:1wxk[/wxcaptcha]
安装jdk mysql Navicat
打开eclipse / window / Preferences / Server / Runtime Environments / Add
选择Apache版本9 → next 路径,jre 选择。
最后应用 Apply and Close
新建项目之后,连接数据库
直接将 mysql-connector-java-8.0.19.jar 粘贴进 WebContent 下 WEB-INF lib 下
项目开始:
数据库设计
代码:
text1.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>主页</title>
<link rel="stylesheet" href="css/stduent.css" type="text/css">
</head>
<body>
<div class="header">
<h1>花店会员管理系统</h1>
</div>
<div class="topnav">
<a href="text1.jsp">主页</a>
<a href="text2.jsp">插入会员信息</a>
<a href="text4.jsp">删除会员信息</a>
<a href="text6.jsp">修改会员信息</a>
<a href="text8.jsp">查询会员信息</a>
<a href="map.html">花店地址</a>
</div>
</body>
</html>
text2.jsp
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.Statement"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
<title>主页</title>
<link rel="stylesheet" href="css/stduent.css" type="text/css">
</head>
<body>
<div class="header">
<h1>花店会员管理系统</h1>
</div>
<div class="topnav">
<a href="text1.jsp">主页</a>
<a href="text2.jsp">插入会员信息</a>
<a href="text4.jsp">删除会员信息</a>
<a href="text6.jsp">修改会员信息</a>
<a href="text8.jsp">查询会员信息</a>
<a href="map.html">花店地址</a>
</div>
<div>
<p>添加会员到数据库</p>
<form action="text3.jsp">
新的会员编号:<input type="text" name="id"><br>
新的会员姓名:<input type="text" name="name"><br>
充值金额:<input type="text" name="math"><br>
购买次数:<input type="text" name="english"><br>
积分:<input type="text" name="physics"><br>
<input type="submit" name="submit" value="提交新的">
</form>
<p>提交想的数据之前的数据表内容</p>
<%
Connection conn=null;
Statement stm=null;
ResultSet rst=null;
try{
Class.forName("com.mysql.cj.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?useSSL=true&serverTimezone=GMT","root","root");
stm=conn.createStatement();
//String sql="select * from score";
rst=stm.executeQuery("select * from score");
out.print("<table border='1'>");
out.print("<tr>");
out.print("<th>编号</th>");
out.print("<th>姓名</th>");
out.print("<th>充值金额</th>");
out.print("<th>购买次数</th>");
out.print("<th>积分</th>");
out.print("</tr>");
while(rst.next()){
out.print("<tr>");
out.print("<th>"+rst.getString("id")+"</th>");
out.print("<th>"+rst.getString(2)+"</th>");
out.print("<th>"+rst.getInt(3)+"</th>");
out.print("<th>"+rst.getInt(4)+"</th>");
out.print("<th>"+rst.getInt(5)+"</th>");
out.print("</tr>");
}
out.print("</table>");
conn.close();
}catch(Exception e){
e.printStackTrace();
}
%>
</div>
</body>
</html>
text3.jsp
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
<title>主页</title>
<link rel="stylesheet" href="css/stduent.css" type="text/css">
</head>
<body>
<div class="header">
<h1>花店会员管理系统</h1>
</div>
<div class="topnav">
<a href="text1.jsp">主页</a>
<a href="text2.jsp">插入会员信息</a>
<a href="text4.jsp">删除会员信息</a>
<a href="text6.jsp">修改会员信息</a>
<a href="text8.jsp">查询会员信息</a>
<a href="map.html">花店地址</a>
</div>
<div>
<p>插入新记录1条</p>
<%
String id=request.getParameter("id");
if(id==null){
id="0000";
}
String name=request.getParameter("name");
if(name==null){
name="无名氏";
}
String math=request.getParameter("math");
if(math==null){
math="0";
}
String english=request.getParameter("english");
if(english==null){
english="0";
}
String physics=request.getParameter("physics");
if(physics==null){
physics="0";
}
Connection conn=null;
Statement stm=null;
ResultSet rst=null;
try{
Class.forName("com.mysql.cj.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?useSSL=true&serverTimezone=GMT","root","root");
stm=conn.createStatement();
String sql="insert into score values('"+id+"','"+name+"','"+math+"','"+english+"','"+physics+"')";
stm.executeUpdate(sql);
rst=stm.executeQuery("select * from score");
out.print("<table border='1'>");
out.print("<tr>");
out.print("<th>编号</th>");
out.print("<th>姓名</th>");
out.print("<th>充值金额</th>");
out.print("<th>购买次数</th>");
out.print("<th>积分</th>");
out.print("</tr>");
while(rst.next()){
out.print("<tr>");
out.print("<th>"+rst.getString("id")+"</th>");
out.print("<th>"+rst.getString(2)+"</th>");
out.print("<th>"+rst.getInt(3)+"</th>");
out.print("<th>"+rst.getInt(4)+"</th>");
out.print("<th>"+rst.getInt(5)+"</th>");
out.print("</tr>");
}
out.print("</table>");
conn.close();
}catch(Exception e){
e.printStackTrace();
}
%>
</div>
</body>
</html>
text4.jsp
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
<title>主页</title>
<link rel="stylesheet" href="css/stduent.css" type="text/css">
</head>
<body>
<div class="header">
<h1>花店会员管理系统</h1>
</div>
<div class="topnav">
<a href="text1.jsp">主页</a>
<a href="text2.jsp">插入会员信息</a>
<a href="text4.jsp">删除会员信息</a>
<a href="text6.jsp">修改会员信息</a>
<a href="text8.jsp">查询会员信息</a>
<a href="map.html">花店地址</a>
</div>
<div class="content">
<p>请输入删除会员的编号</p>
<form action="text5.jsp">
<input type="text" name="id">
<input type="submit" name="submit" value="提交编号">
</form>
<p>删除记录前的会员信息</p>
<%
Connection conn=null;
Statement stm=null;
ResultSet rst=null;
try{
Class.forName("com.mysql.cj.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?useSSL=true&serverTimezone=GMT","root","root");
stm=conn.createStatement();
String sql="select * from score";
rst=stm.executeQuery(sql);
out.print("<table border='1'>");
out.print("<tr>");
out.print("<th width='100'>编号</th>");
out.print("<th width='100'>姓名</th>");
out.print("<th width='100'>充值金额</th>");
out.print("<th width='100'>购买次数</th>");
out.print("<th width='100'>积分</th>");
out.print("</tr>");
while(rst.next()){
out.print("<tr>");
out.print("<th>"+rst.getString("id")+"</th>");
out.print("<th>"+rst.getString(2)+"</th>");
out.print("<th>"+rst.getInt(3)+"</th>");
out.print("<th>"+rst.getInt(4)+"</th>");
out.print("<th>"+rst.getInt(5)+"</th>");
out.print("</tr>");
}
out.print("</table>");
conn.close();
}catch(Exception e){
e.printStackTrace();
}
%>
</div>
</body>
</html>
text5.jsp
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
<title>主页</title>
<link rel="stylesheet" href="css/stduent.css" type="text/css">
</head>
<body>
<div class="header">
<h1>花店会员管理系统</h1>
</div>
<div class="topnav">
<a href="text1.jsp">主页</a>
<a href="text2.jsp">插入会员信息</a>
<a href="text4.jsp">删除会员信息</a>
<a href="text6.jsp">修改会员信息</a>
<a href="text8.jsp">查询会员信息</a>
<a href="map.html">花店地址</a>
</div>
<div class="content">
<%
Connection conn=null;
Statement stm=null;
ResultSet rst=null;
String id=request.getParameter("id");
try{
Class.forName("com.mysql.cj.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?useSSL=true&serverTimezone=GMT","root","root");
stm=conn.createStatement();
String str="delete from score where id='"+id+"'";
stm.executeUpdate(str);
out.print("删除记录后的会员信息");
String sql="select * from score";
rst=stm.executeQuery(sql);
out.print("<table border='1'>");
out.print("<tr>");
out.print("<th width='100'>编号</th>");
out.print("<th width='100'>姓名</th>");
out.print("<th width='100'>充值金额</th>");
out.print("<th width='100'>购买次数</th>");
out.print("<th width='100'>积分</th>");
out.print("</tr>");
while(rst.next()){
out.print("<tr>");
out.print("<th>"+rst.getString("id")+"</th>");
out.print("<th>"+rst.getString(2)+"</th>");
out.print("<th>"+rst.getInt(3)+"</th>");
out.print("<th>"+rst.getInt(4)+"</th>");
out.print("<th>"+rst.getInt(5)+"</th>");
out.print("</tr>");
}
out.print("</table>");
}catch(Exception e){
e.printStackTrace();
}finally{
if(conn!=null){
conn.close();
}
}
%>
</div>
</body>
</html>
文章目录
关闭
什么幌子
干货
admin@什么幌子
o(* ̄︶ ̄*)o