1、实体类

package com.edu.empity;

public class People {
private String hubie;
private String livetype;
private String area;
private String roomnum;
private String name;
private String idcard;
private String sex;
private String nation;
private String education;
public String getHubie() {
return hubie;
}
public void setHubie(String hubie) {
this.hubie = hubie;
}
public String getLivetype() {
return livetype;
}
public void setLivetype(String livetype) {
this.livetype = livetype;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public String getRoomnum() {
return roomnum;
}
public void setRoomnum(String roomnum) {
this.roomnum = roomnum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIdcard() {
return idcard;
}
public void setIdcard(String idcard) {
this.idcard = idcard;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getNation() {
return nation;
}
public void setNation(String nation) {
this.nation = nation;
}
public String getEducation() {
return education;
}
public void setEducation(String education) {
this.education = education;
}
public People(String hubie, String livetype, String area, String roomnum, String name, String idcard, String sex,
String nation, String education) {
super();
this.hubie = hubie;
this.livetype = livetype;
this.area = area;
this.roomnum = roomnum;
this.name = name;
this.idcard = idcard;
this.sex = sex;
this.nation = nation;
this.education = education;
}
public People() {
// TODO 自动生成的构造函数存根
}

}

2、dao层

package com.edu.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.edu.dbu.DBUtil;
import com.edu.empity.People;

public class Peopledao {

public List<People> getallPeople() {
List<People> list = new ArrayList<People>();
Connection conn = null;
conn = DBUtil.getConnection();
PreparedStatement pst =null;
ResultSet rs = null;
String sql = "select * from people";
try {
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
while(rs.next()) {
People people = new People();
people.setHubie(rs.getString("hubie"));
people.setHubie(rs.getString("hubie"));
people.setHubie(rs.getString("hubie"));
people.setHubie(rs.getString("hubie"));
people.setHubie(rs.getString("hubie"));
people.setHubie(rs.getString("hubie"));
people.setHubie(rs.getString("hubie"));
}
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}

return list;
}

public boolean Addpeople(People people) throws SQLException {
// TODO 自动生成的方法存根
String sql = "insert into people(hubie,livetype,area,roomnum,name,idcard,sex,nation,education)values(?,?,?,?,?,?,?,?,?)";
Connection conn = DBUtil.getConnection();
PreparedStatement pst =null;
int p =0;
try {
pst = conn.prepareStatement(sql);
pst.setString(1, people.getHubie());
pst.setString(2, people.getLivetype());
pst.setString(3, people.getArea());
pst.setString(4, people.getRoomnum());
pst.setString(5, people.getName());
pst.setString(6, people.getIdcard());
pst.setString(7, people.getSex());
pst.setString(8, people.getNation());
pst.setString(9, people.getEducation());
p = pst.executeUpdate();
pst.close();
conn.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}finally {
if(p != 0) {
System.out.println("dao信息添加成功");
}
}
return true;
}
public boolean Updatepeople(People people) throws SQLException {
// TODO 自动生成的方法存根
Connection conn = DBUtil.getConnection();
String sql = "update people set hubie=? livetype=? area=? roomnum=? idcard=? sex=? nation=? education=? where name = ?";
PreparedStatement pst =null;
int p =0;
try {
pst = conn.prepareStatement(sql);
pst.setString(1, people.getHubie());
pst.setString(2, people.getLivetype());
pst.setString(3, people.getArea());
pst.setString(4, people.getRoomnum());
pst.setString(5, people.getIdcard());
pst.setString(6, people.getSex());
pst.setString(7, people.getNation());
pst.setString(8, people.getEducation());
pst.setString(9, people.getName());
p = pst.executeUpdate();
pst.close();
conn.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}finally {
if(p != 0) {
System.out.println("dao信息修改成功");
}
}
return true;
}
public boolean Deletepeople(String name) throws SQLException {
// TODO 自动生成的方法存根
Connection conn = DBUtil.getConnection();
String sql = "delete from people where name = ?";
PreparedStatement pst =null;
int p =0;
try {
pst = conn.prepareStatement(sql);
pst.setString(1, name);
p = pst.executeUpdate();
pst.close();
conn.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}finally {
if(p != 0) {
System.out.println("dao信息删除成功");
}
}
return true;
}
}

3、servlet

1)Add

package com.edu.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.dao.Peopledao;
import com.edu.empity.People;

@WebServlet("/Addservlet")
public class Addservlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String hubie = request.getParameter("hubie");
String livetype = request.getParameter("livetype");
String area = request.getParameter("area");
String roomnum = request.getParameter("roomnum");
String name = request.getParameter("name");
String idcard = request.getParameter("idcard");
String sex = request.getParameter("sex");
String nation = request.getParameter("nation");
String education = request.getParameter("education");
System.out.println(hubie+livetype+area+roomnum+name+idcard+sex+nation+education);
Peopledao dao = new Peopledao();
People people = new People(hubie,livetype,area,roomnum,name,idcard,sex,nation,education);
boolean flag = false;
try {
flag=dao.Addpeople(people);
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}finally {
if(flag) {
System.out.println("servlet信息添加成功");
}
}
request.getRequestDispatcher("showpeople.jsp").forward(request, response);

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

}

2)delete

package com.edu.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.dao.Peopledao;

@WebServlet("/Deleteservlet")
public class Deleteservlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String name = request.getParameter("name");
Peopledao dao = new Peopledao();
try {
if(name!=null) {
dao.Deletepeople(name);
}
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
request.getRequestDispatcher("showpeople.jsp").forward(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

}

3)update

package com.edu.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.dao.Peopledao;
import com.edu.empity.People;

@WebServlet("/Updateservlet")
public class Updateservlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String hubie = request.getParameter("hubie");
String livetype = request.getParameter("livetype");
String area = request.getParameter("area");
String roomnum = request.getParameter("roomnum");
String name = request.getParameter("name");
String idcard = request.getParameter("idcard");
String sex = request.getParameter("sex");
String nation = request.getParameter("nation");
String education = request.getParameter("education");
People people = new People(hubie,livetype,area,roomnum,name,idcard,sex,nation,education);
Peopledao dao = new Peopledao();
try {
if(name != null) {
dao.Updatepeople(people);
}
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
request.getRequestDispatcher("showpeople.jsp").forward(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

}

1120day-户别确认的更多相关文章

  1. Access一些常用的SQL语句

    您可以将 Microsoft Office Access 2013 用作创建.修改数据库以及处理数据的工具,还可将 Office Access 2013 用作服务器数据库管理系统(如 Microsof ...

  2. DOS程序员手册(九)

    第14章参考手册概述     本书余下的章节将向读者们介绍BIOS.DOS各种各样API函数和服务,作为一名程 序员,了解和掌握这些知识是很有好处的.在所介绍的参考手册中,每部手册都汇集了大 量的资源 ...

  3. 二级Parser应用教程

    01 应用背景 Ubidots是一个物联网云平台,通过设备友好的API(可通过HTTP / MQTT / TCP / UDP协议访问)简单安全地将硬件和数字输入连接到Ubidots Cloud. 它可 ...

  4. TCP三次握手Linux源码解析

    TCP是面向连接的协议.面向连接的传输层协议在原点和重点之间建立了一条虚拟路径,同属于一个报文的所有报文段都沿着这条虚拟路径发送,为整个报文使用一条虚拟路径能够更容易地实施确认过程以及对损伤或者丢失报 ...

  5. 08_Linux基础-vim-tmux-字符编码

    @ 目录 08_Linux基础-vim-tmux-字符编码 一. vim vim编辑器作用 vim模式 vim命令模式 vim编辑模式 vim末行模式 vim视图模式 vim替换模式 练习 vim常用 ...

  6. 解析大型.NET ERP系统 电子邮件系统帐户集成

    为保证ERP系统的信息流准确快速的传递,需要给系统设计一个消息盒子机制.当系统中发生业务操作后,需要提醒下一个环节的操作人员,以保证ERP信息流快速准确传递.比如生产任务单(工作单,加工单,制单)过帐 ...

  7. ZSDR017-客户订货价格和库存

    *----------------------------------------------------------------------*ZSDR017-客户订货价格和库存*---------- ...

  8. Win7家庭版开启Administrator管理员帐户的方法

    Win7家庭版开启Administrator管理员帐户的方法 发布时间:2014-11-17 18:30:06来源:系统盒浏览数:2786 很多用户安装好Win7系统第一步就是开启Administra ...

  9. win7 IIS7.0 【IIS 管理器无法验证此内置帐户是否有访问权】

    异常信息: 服务器配置为将传递身份验证和内置帐户一起使用,以访问指定的物理路径.但是,IIS 管理器无法验证此内置帐户是否有访问权.请确保应用程序池标识具有该物理路径的读取访问权.如果此服务器加入到域 ...

  10. 为什么我的outlook只能收信不能发信,发送测试电子邮件消息: 无法发送此邮件。请在帐户属性中验证电子邮件

    链接地址:http://zhidao.baidu.com/link?url=aVIFo2aNLuHIZGZuEUataHkZp4XApHqyvbEK8ACHPhi3jwhGhM0GBAtm72AnsP ...

随机推荐

  1. CF254A Cards with Numbers 题解

    Content 有 \(2n\) 个数,让你找出两两相等的 \(n\) 对数的编号,或者方案不存在. 数据范围:\(1\leqslant n\leqslant 3\times 10^5,1\leqsl ...

  2. CF803B Distances to Zero 题解

    Content 有一个长度为 \(n\) 的序列 \(a_1,a_2,a_3,...,a_n\),求每个数与它最近的 \(0\) 的距离(\(0\) 的距离为 \(0\)). 数据范围:\(1\leq ...

  3. sar命令查看网卡流量 (System ActivityReporter系统活动情况报告)

    sar命令查看网卡流量 2016年06月14日 03:31:29 WarriorTan 阅读数:9748更多 个人分类: Linux   版权声明:本文为博主原创文章,未经博主允许不得转载. http ...

  4. 【LeetCode】1134. Armstrong Number 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 直接计算 日期 题目地址:https://leetco ...

  5. 【LeetCode】312. Burst Balloons 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/burst-ba ...

  6. 【LeetCode】819. Most Common Word 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 正则+统计 日期 题目地址:https://leet ...

  7. hdu-5569matrix(dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=5569; 题目意思: 从(1,1)点出发只能向右和向下走,到达(n,n)点时所得到的价值最小, 价值是Let th ...

  8. 第七个知识点:随机性如何辅助计算和什么是BPP类问题

    第七个知识点:随机性如何辅助计算和什么是BPP类问题 原文地址:http://bristolcrypto.blogspot.com/2014/11/52-things-number-7-how-doe ...

  9. 第三十一个知识点:Game Hopping证明

    第三十一个知识点:Game Hopping证明 关于安全证明, 目前主流的方法有安全归约证明 (由 single game 实现) 和 Game Hopping (由 game sequence 实现 ...

  10. Spring练习,使用Properties类型注入方式,注入MySQL数据库连接的基本信息,然后使用JDBC方式连接数据库,模拟执行业务代码后释放资源,最后在控制台输出打印结果。

    相关 知识 >>> 相关 练习 >>> 实现要求: 使用Properties类型注入方式,注入MySQL数据库连接的基本信息,然后使用JDBC方式连接数据库,模拟执 ...