2019软工期中考试初版实现
第七次全国人口普查登记(20分)
1、项目需求:
开展第七次全国人口普查,将为编制“十四五”规划提供重要信息支持;推动实现人口与经济社会、资源环境协调发展,为深化供给侧结构性改革,推动经济高质量发展,建设现代化经济体系提供强有力的支持;人口普查还将为完善人口发展战略和政策体系,促进人口长期均衡发展提供重要信息支持。
2.系统要求与功能设计
2.1 页面功能要求
(1)能够在Tomcat服务器中正确部署,并通过浏览器查看;(1分)
(2)网站页面整体风格统一;
图1 人口普查系统功能结构图
(3)主页面:要求显示人口登记、修改人口信息、删除人口信息、查询人口信息,人口信息浏览五个子菜单。(1分)
(4)人口登记页面:(6分)
①完成添加人口信息登记,基本信息和填报限制如下表所示
户 别 |
家庭户 集体户(单选框) |
住房类型 |
家庭住宅、集体住所、工作地住所、其他住宅、无住宅(单选框) |
本户现住房面积 |
XXXXX平方米(文本框,只能输入这个整数) |
本户现住房间数 |
XXXXX间(文本框,只能输入这个整数) |
户主姓名 |
XXXXX(文本框) |
身份证号码 |
XXXXXXXXXXXXXXXXXX(判断身份证位数13位并且只能录入数字、最后一位可以录入X) |
性别 |
男/女(单选框) |
民族 |
(文本框) |
受教育程度 |
研究生、大学本科、大学专科、高中、初中、小学、未上过学(下拉框实现) |
②点击“提交”按钮,保存成功则跳转到人口基本信息浏览界面,新录入的信息置顶显示。失败则提示错误信息,返回当前页面
评分标准:
①完成人口登记页面(未完成0分,完成1分)
②保存人口信息入库(未完成0分,完成1分)
③户别、住房类别、性别实现一个单选框录入0.5分,全部实现1分。(未完成0分,完成一个0.5,全部完成1分)
④本户现住房面积或本户现住房间数实现整数判断(未完成0分,完成0.5分)
⑤判断身份证按照要求录入,实现位数和数字录入判断0.5分,实现最后一位可以输入数字或X判断0.5分。(1分)
⑥受教育程度下拉框录入(未完成0分,完成0.5分)
⑦提交后页面跳转功能;(未完成0分,完成1分)
(5)修改人口信息页面:(3分)
输入户主姓名,显示其余信息,可对身份证号码、性别、民族、受教育程度进行修改。(身份证号码、性别、受教育程度必须符合录入要求);如果该名户主信息数据库不存在,则提示“该户主信息不存在”。(3分)
评分标准:
①完成修改户主个人信息页面(未完成0分,完成0.5分)
② 实现数据库中信息更新(未完成0分,完成1分)
③修改信息判断是否符合要求。(未完成0分,完成0.5分)
④输入姓名,显示其余信息,若该信息不存在,提示错误信息;(未完成0分,完成1分)
(6)删除人口信息页面:录入户主姓名,显示详细信息后,点击“删除”按钮,弹出提示框,提示“是否确认删除该户主信息”,确认后删除该信息。(1分)
评分标准:
①输入户主姓名可显示其余信息。(未完成0分,完成0.5分)
②对应删除数据库中信息(未完成0分,完成0.5分)
(7)浏览人口信息页面:(2分)
以列表形式显示人口基本信息,结果列表中显示姓名、性别,民族、受教育程度基本信息,点击姓名,可以跳转到个人详细信息。
①实现以列表形式显示人口基本信息,结果列表中显示姓名、性别,民族、受教育程度基本信息(未完成0分,完成1分)
②实现跳转个人详细信息页面。(未完成0分,完成1分)
(8)查询人口信息页面:(3分)
要求可以根据人口姓名、性别、民族、受教育程度四种条件实现模糊查询,输出结果以列表形式显示,显示人口姓名、性别、民族、受教育程度基本信息,点击列表中的姓名,跳转到人口个人详细信息页面。
评分标准:
①缺少一种查询条件扣除1分。(未完成0分,完成3分)
2.2 功能要求
(1)设计出合理的数据库和数据表,要求使用mysql、sqlserver、oracle三种数据库中一种(1分)
(2)使用Serverlet实现页面交互(1分)。
(3)使用Java Bean封装数据库连接操作(1分。)
web页面的jsp文件与html文件
主页面 zhu.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>人口普查系统</title>
</head>
<body>
<form action="dengji.html" method="get">
<table align="center" border="1" width="10000">
<p align="center">
<input type="submit" value="信息登记" />
</table>
</p>
</form>
<form action="xiugai.jsp" method="get">
<table align="center" border="2" width="10000">
<p align="center">
<input type="submit" value="信息修改" />
</table>
</p>
</form>
<form action="shanchu.jsp" method="get">
<table align="center" border="2" width="10000">
<p align="center">
<input type="submit" value="信息删除" />
</table>
</p>
</form>
<form action="chaxun.jsp" method="get">
<table align="center" border="1" width="10000">
<p align="center">
<input type="submit" value="信息查询" />
</table>
</p>
</form>
<form action="liulan.jsp" method="get">
<table align="center" border="1" width="10000">
<p align="center">
<input type="submit" value="浏览信息" />
</table>
</p>
</form>
</body>
</html>
登记页面 dengji.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>人口登记页面</title> </head> <body> <div align="center"> <form action="dengji" method="post"> <tr> <font face="楷体" size="7" color="blue">人口普查系统登记页面</font> </tr> <table align="center"> <tr> <td>户别:</td> <td> <input type="radio" name="hubie" value="家庭户">家庭户<br> <input type="radio" name="hubie" value="集体户" checked>集体户 </td> </tr> <tr> <td>住房类型:</td> <td> <input type="radio" name="leixing" value="家庭住宅">家庭住所<br> <input type="radio" name="leixing" value="集体住所" >集体住所<br> <input type="radio" name="leixing" value="工作地住所">工作地住所<br> <input type="radio" name="leixing" value="其他住宅">其他住宅<br> <input type="radio" name="leixing" value="无住宅"checked>无住宅 </td> </tr> <tr> <td>本户现住房面积:</td> <td> <input type="text" name="mianji"> </tr> <tr> <td>本户现住房间数:</td> <td> <input type="text" name="number"> </tr> <tr> <td>户主姓名:</td> <td> <input type="text" name="name"> </tr> <tr> <td>身份证号码:</td> <td> <input type="text" name="id" onblur="isCardxuehao(this.value)"> </td> </tr> <tr> <td>性别:</td> <td> <input type="radio" name="sex" value="男">男<br> <input type="radio" name="sex" value="女" checked>女 </td> </tr> <tr> <td>民族:</td> <td> <input type="text" name="minzu"> </td> </tr> <tr> <td>受教育程度:</td> <td> <select name="jiaoyu"> <option value="研究生">研究生</option> <option value="大学本科">大学本科</option> <option value="大学专科">大学专科</option> <option value="高中">高中</option> <option value="初中">初中</option> <option value="小学">小学</option> <option value="未上过学"selected>未上过学</option> </select> </td> </tr> <tr> <td colspan="2"><div align="center"> <input type="submit" value="录入"> </div> </td> </tr> </form> </div> </body> <script type="text/javascript"> function isCardxuehao(card) { var reg = /(^\d{18}$)|(^\d{17}(\d|X|x)$)/; if(reg.test(card) === false) { alert("身份证号输入不合法"); document.getElementById('id').value=""; } } </script> </html>
查询页面的chaxun.jsp和chaxun1.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>用户查询页面</title> </head> <body> <tr> <form action="chaxun1.jsp" method="get"> <table align="center" border="1" width="500"> <td>请输入需要查询住户的姓名 : </td> <td> <input type="text" name="name" size="12" maxlength="20" /> </td> </tr> <tr> <tr> <td colspan="2"><div align="center"> <input type="submit" value="查询"> </div> </td> </tr> </form> <tr> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <% String name = request.getParameter("name"); //接收客户端传递过来的参数 try { Class.forName("com.mysql.jdbc.Driver"); ////驱动程序名 String url = "jdbc:mysql://localhost:3306/zjr?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; //数据库名 ?后面的是为了指定字符的编码、解码格式。 String username = "root"; //数据库用户名 String password = "Zhaowenzhe1007"; //数据库用户密码 Connection conn = DriverManager.getConnection(url, username, password); //连接状态 if(conn != null){ Statement stmt = null; ResultSet rs = null; String sql = "select *from people where people.name like '%"+name+"%';"; //查询语句 stmt = conn.createStatement(); rs = stmt.executeQuery(sql); out.print("<br />"); out.print("<br />"); while (rs.next()) { out.println("户别: "+rs.getString("hubie")+"   "+"住房类型: "+rs.getString("leixing")+"   "+"房屋面积: "+rs.getString("mianji")+"   "+"现居住房间数: "+rs.getString("number")+"   "+"住户姓名: "+rs.getString("name")+"   "+"住户身份证号: "+rs.getString("id")+"   "+"住户性别: "+rs.getString("sex")+"   "+"民族: "+rs.getString("minzu")+"   "+"受教育程度:"+rs.getString("jiaoyu")+" "); //将查询结果输出 out.print("<br/>"); } } else{ out.print("连接失败!"); } }catch (ClassNotFoundException e) { e.printStackTrace(); }catch (SQLException e){ e.printStackTrace(); } %> </body> </html>
浏览全部信息页面 liulan.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <% //接收客户端传递过来的参数 try { Class.forName("com.mysql.jdbc.Driver"); ////驱动程序名 String url = "jdbc:mysql://localhost:3306/zjr?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; //数据库名 ?后面的是为了指定字符的编码、解码格式。 String username = "root"; //数据库用户名 String password = "Zhaowenzhe1007"; //数据库用户密码 Connection conn = DriverManager.getConnection(url, username, password); //连接状态 if(conn != null){ Statement stmt = null; ResultSet rs = null; String sql = "select * from people;"; //查询语句 stmt = conn.createStatement(); rs = stmt.executeQuery(sql); out.print("<br />"); out.print("<br />"); while (rs.next()) { out.println("户别: "+rs.getString("hubie")+"   "+"住房类型: "+rs.getString("leixing")+"   "+"房屋面积: "+rs.getString("mianji")+"   "+"现居住房间数: "+rs.getString("number")+"   "+"住户姓名: "+rs.getString("name")+"   "+"住户身份证号: "+rs.getString("id")+"   "+"住户性别: "+rs.getString("sex")+"   "+"民族: "+rs.getString("minzu")+"   "+"受教育程度:"+rs.getString("jiaoyu")+" "); //将查询结果输出 out.print("<br/>"); } } else{ out.print("连接失败!"); } }catch (ClassNotFoundException e) { e.printStackTrace(); }catch (SQLException e){ e.printStackTrace(); } %> </body> </html>
删除下的shanchu.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>用户删除页面</title>
</head>
<body>
<tr>
<form action="dengji1" method="post">
<table align="center" border="1" width="500">
<td>请输入需要删除住户的姓名 : </td>
<td>
<input type="text" name="name" size="12" maxlength="20"/>
</td>
</form>
</tr>
<tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="删除">
</div>
</td>
</tr>
</form>
<tr>
</body>
</html>
修改功能的xiugai.jsp以及xiugai1.html
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="GB18030">
<title>Insert title here</title>
</head>
<body>
<tr>
<form action="xiugai1.html" method="get">
<table align="center" border="1" width="500">
<td>请输入需要修改住户的姓名 : </td>
<td>
<input type="text" name="name" size="12" maxlength="20"/>
</td>
</form>
</tr>
<tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="修改信息">
</div>
</td>
</tr>
</form>
<tr>
</body>
</html>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <div align="center"> <tr> <h2>人口普查系统修改页面</h2> </tr> <form action="dengji2" method="post"> <table align="center"> <tr> <td>户别:</td> <td> <input type="radio" name="hubie" value="家庭户">家庭户<br> <input type="radio" name="hubie" value="集体户">集体户 </td> </tr> <tr> <td>住房类型:</td> <td> <input type="radio" name="leixing" value="家庭住宅">家庭住所<br> <input type="radio" name="leixing" value="集体住所" >集体住所<br> <input type="radio" name="leixing" value="工作地住所">工作地住所<br> <input type="radio" name="leixing" value="其他住宅">其他住宅<br> <input type="radio" name="leixing" value="无住宅">无住宅 </td> </tr> <tr> <td>本户现住房面积:</td> <td> <input type="text" name="mianji"> </tr> <tr> <td>本户现住房间数:</td> <td> <input type="text" name="number"> </tr> <tr> <td>户主姓名:</td> <td> <input type="text" name="name"> </tr> <tr> <td>身份证号码:</td> <td> <input type="text" name="id" onblur="isCardxuehao(this.value)"> </td> </tr> <tr> <td>性别:</td> <td> <input type="radio" name="sex" value="男">男<br> <input type="radio" name="sex" value="女">女 </td> </tr> <tr> <td>民族:</td> <td> <input type="text" name="minzu"> </td> </tr> <tr> <td>受教育程度:</td> <td> <select name="jiaoyu"> <option value="研究生">研究生</option> <option value="大学本科">大学本科</option> <option value="大学专科">大学专科</option> <option value="高中">高中</option> <option value="初中">初中</option> <option value="小学">小学</option> <option value="未上过学"selected>未上过学</option> </select> </td> </tr> <tr> <td colspan="2"><div align="center"> <input type="submit" value="录入"> </div> </td> </tr> </form> </div> </body> <script type="text/javascript"> function isCardxuehao(card) { var reg = /(^\d{18}$)/; if(reg.test(card) === false) { alert("身份证号输入不合法"); document.getElementById('id').value=""; } } </script> </html>
Serlvet下的修改添加删除文件 添加dengji 删除dengji1 修改dengji2
package Servlet; import java.io.IOException; import java.sql.SQLException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import com.Dao.tianjia; import com.Bean.jia; /** * Servlet implementation class dengji */ @WebServlet("/dengji")//对应html中的action表单 public class dengji extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public dengji() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); //设置相应的文本类型 response.setContentType("text/html;charset=utf-8");//设置响应类型,并防止中文乱码 tianjia A =new tianjia(); int i = 0; String hubie=request.getParameter("hubie"); String leixing = request.getParameter("leixing"); String mianji = request.getParameter("mianji"); String number = request.getParameter("number"); String name = request.getParameter("name"); String id = request.getParameter("id"); String sex = request.getParameter("sex"); String minzu = request.getParameter("minzu"); String jiaoyu = request.getParameter("jiaoyu"); jia B = new jia(); B.setName(name); B.setNumber(number); B.setMianji(mianji); B.setLeixing(leixing); B.setSex(sex); B.setMinzu(minzu); B.setJiaoyu(jiaoyu); B.setId(id); B.setHubie(hubie); try { i=A.add(B); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if(i==1) response.getWriter().append("添加成功!"); else response.getWriter().append("添加失败!"); } }
package Servlet; import java.io.IOException; import java.sql.SQLException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import com.Dao.sc; import com.Bean.jian; /** * Servlet implementation class dengji */ @WebServlet("/dengji1")//对应html中的action表单 public class dengji1 extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public dengji1() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); //设置相应的文本类型 response.setContentType("text/html;charset=utf-8");//设置响应类型,并防止中文乱码 sc A =new sc(); int i = 0; String name = request.getParameter("name"); jian B = new jian(); B.setName(name); try { i=A.delete(B); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if(i==1) response.getWriter().append("删除成功!"); else response.getWriter().append("删除失败!"); } }
package Servlet; import java.io.IOException; import java.sql.SQLException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import com.Dao.xg; import com.Bean.jia; /** * Servlet implementation class dengji */ @WebServlet("/dengji2")//对应html中的action表单 public class dengji2 extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public dengji2() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); //设置相应的文本类型 response.setContentType("text/html;charset=utf-8");//设置响应类型,并防止中文乱码 xg A =new xg(); int i = 0; String hubie=request.getParameter("hubie"); String leixing = request.getParameter("leixing"); String mianji = request.getParameter("mianji"); String number = request.getParameter("number"); String name = request.getParameter("name"); String id = request.getParameter("id"); String sex = request.getParameter("sex"); String minzu = request.getParameter("minzu"); String jiaoyu = request.getParameter("jiaoyu"); // System.out.println(leixing); // System.out.println(hubie); jia B = new jia(); B.setName(name); B.setNumber(number); B.setMianji(mianji); B.setLeixing(leixing); B.setSex(sex); B.setMinzu(minzu); B.setJiaoyu(jiaoyu); B.setId(id); B.setHubie(hubie); // System.out.println(B.getHubie()); // System.out.println(B.getName()); // System.out.println(B.getSex()); // System.out.println(B.getNumber()); // System.out.println(B.getJiaoyu()); System.out.println(B.getId()); try { i=A.update(B); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if(i==1) response.getWriter().append("修改成功!"); else response.getWriter().append("修改失败!"); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } }
com.Util下的utils文件,用来管理数据库工具
package com.Util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * JDBC快速入门 */ public class utils { public static Connection getConnection() throws ClassNotFoundException, SQLException { Connection connection = null;//连接数据库 PreparedStatement ps = null;//Statement 对象用于将 SQL 语句发送到数据库中。 ResultSet rs = null; //1. 导入驱动jar包 //2.注册驱动 // Class.forName("com.mysql.cj.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/zjr?serverTimezone=UTC","root", "Zhaowenzhe1007");//修改你的数据库名称以及密码 return connection; } public static void close(Connection connection ) { try { if (connection != null) { connection.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void close(PreparedStatement preparedStatement ) { try { if (preparedStatement != null) { preparedStatement.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void close(ResultSet resultSet ) { try { if (resultSet != null) { resultSet.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
封装对象使用的com.Bean下的复制添加修改的jia.java和删除的jian.java
package com.Bean; public class jia { private String hubie; private String leixing; private String mianji; private String number; private String name; private String id; private String sex; private String minzu; private String jiaoyu; public String getHubie() { return hubie; } public void setHubie(String hubie) { this.hubie = hubie; } public String getLeixing() { return leixing; } public void setLeixing(String leixing) { this.leixing = leixing; } public String getMianji() { return mianji; } public void setMianji(String mianji) { this.mianji = mianji; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getMinzu() { return minzu; } public void setMinzu(String minzu) { this.minzu = minzu; } public String getJiaoyu() { return jiaoyu; } public void setJiaoyu(String jiaoyu) { this.jiaoyu = jiaoyu; } }
package com.Bean; public class jian { String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
com.Dao包下的添加修改删除的sql语句传递工具sc.java tianjia.java xg.java
package com.Dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import com.Bean.jian; import com.Util.utils; public class sc { // TODO Auto-generated method stub public int delete(jian A) throws Exception { Connection connection = utils.getConnection(); String sql = "delete from people where name=?";//删除你的表格内容 PreparedStatement preparedStatement = null; int i=0; try { //创建语句传输对象 preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, A.getName()); i = preparedStatement.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { } return i; } }
package com.Dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import com.Bean.jia; import com.Util.utils; public class tianjia{ // TODO Auto-generated method stub public int add(jia A) throws Exception { Connection connection = utils.getConnection(); String sql = "insert into people values(?,?,?,?,?,?,?,?,?)";//修改你的表格名称 PreparedStatement preparedStatement = null; int i=0; try { //创建语句传输对象 preparedStatement = connection.prepareStatement(sql); // preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, A.getHubie()); preparedStatement.setString(2, A.getLeixing()); preparedStatement.setString(3, A.getMianji()); preparedStatement.setString(4, A.getNumber()); preparedStatement.setString(5,A.getName()); preparedStatement.setString(6, A.getId()); preparedStatement.setString(7, A.getSex()); preparedStatement.setString(8, A.getMinzu()); preparedStatement.setString(9, A.getJiaoyu()); i = preparedStatement.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { } return i; } }
package com.Dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import com.Bean.jia; import com.Util.utils; public class xg { // TODO Auto-generated method stub public int update(jia A) throws Exception { Connection connection = utils.getConnection(); String sql = "update people set hubie=?,leixing=?,mianji=?,number=?,id=?,sex=?,minzu=?,jiaoyu=? where name=?";//修改你的表格名称 PreparedStatement preparedStatement = null; int i=0; try { //创建语句传输对象 preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, A.getHubie()); preparedStatement.setString(2, A.getLeixing()); preparedStatement.setString(3, A.getMianji()); preparedStatement.setString(4, A.getNumber()); preparedStatement.setString(5, A.getId()); preparedStatement.setString(6, A.getSex()); preparedStatement.setString(7, A.getMinzu()); preparedStatement.setString(8, A.getJiaoyu()); preparedStatement.setString(9,A.getName()); i = preparedStatement.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { } //connection.commit(); // preparedStatement.close(); //connection.close(); return i; } }
本次作业初步了解了web页面传递数据的增删改查,但此次仍然有很多没有完成的小细节,仅仅完成了系统所需的大功能,弹窗确认是否删除,查询信息先进行简略信息查询,再进入详细查询,模糊查询,web页面的表格美观整理这些目前都没有实现,这也是接下来需要努力的方向。