zoukankan      html  css  js  c++  java
  • 1010day人口普查系统

    1、xiugai.java

    package com.edu.ia;

    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;

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

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    String name=request.getSession().getAttribute("name").toString();
    String ID=request.getParameter("ID");
    String sex=request.getParameter("sex");
    String nation=request.getParameter("nation");
    String educator=request.getParameter("educator");
    hand L=new hand();
    try {
    L.update(name, ID, sex, nation, educator);
    request.getRequestDispatcher("jieguo.jsp").forward(request, response);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
    }

    }

    2、shanchu.java

    package com.edu.ia;

    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;

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

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    String name=request.getParameter("name");
    hand L=new hand();
    try {
    L.delete(name);
    request.getRequestDispatcher("getResult.jsp").forward(request, response);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
    }

    }

    3、People.java

    package com.edu.ia;

    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;

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


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    String hubie=request.getParameter("hubie");
    String zhufang=request.getParameter("zhufang");
    String mianji=request.getParameter("mianji");
    String fangjianshu=request.getParameter("fangjianshu");
    String name=request.getParameter("name");
    String ID=request.getParameter("ID");
    String sex=request.getParameter("sex");
    String nation=request.getParameter("nation");
    String educator=request.getParameter("educator");
    get login=new get(hubie,zhufang,mianji,fangjianshu,name,ID,sex,nation,educator);
    hand L=new hand();
    try {
    L.insert(login);
    request.getRequestDispatcher("Browse.jsp").forward(request, response);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
    }

    }

    4、hand.java

    package com.edu.ia;

    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;

    public class hand {
    public void insert(get L) throws SQLException {
    String sql = "insert into test(hubie,zhufang,mianji,fangjianshu,name,ID,sex,nation,educator)values(?,?,?,?,?,?,?,?,?)";
    Connection connection = DBUtil.getConnection();
    PreparedStatement preparedStatement = null;
    preparedStatement = connection.prepareStatement(sql);
    preparedStatement.setString(1,L.getHubie());
    preparedStatement.setString(2,L.getZhufang());
    preparedStatement.setString(3,L.getMianji());
    preparedStatement.setString(4,L.getFangjianshu());
    preparedStatement.setString(5,L.getName());
    preparedStatement.setString(6,L.getID());
    preparedStatement.setString(7,L.getSex());
    preparedStatement.setString(8,L.getNation());
    preparedStatement.setString(9,L.getEducator());
    preparedStatement.execute();
    }
    public void update(String name,String ID,String sex,String nation,String educator) throws SQLException {
    String sql="UPDATE test SET ID=?,sex=?,nation=?,educator=? where name=?";
    Connection conn= DBUtil.getConnection();
    PreparedStatement papre=conn.prepareStatement(sql);
    papre.setString(1, ID);
    papre.setString(2, sex);
    papre.setString(3, nation);
    papre.setString(4, educator);
    papre.setString(5, name);
    papre.execute();
    }
    public void delete(String name) throws SQLException {
    String sql="delete from test where name=?";
    Connection conn= DBUtil.getConnection();
    PreparedStatement papre=conn.prepareStatement(sql);
    papre.setNString(1, name);
    papre.execute();
    }
    }

    5、get.java

    package com.edu.ia;

    public class get {
    String hubie;
    String zhufang;
    String mianji;
    String fangjianshu;
    String name;
    String ID;
    String sex;
    String nation;
    String educator;
    public String getHubie() {
    return hubie;
    }
    public void setHubie(String hubie) {
    this.hubie = hubie;
    }
    public String getZhufang() {
    return zhufang;
    }
    public void setZhufang(String zhufang) {
    this.zhufang = zhufang;
    }
    public String getMianji() {
    return mianji;
    }
    public void setMianji(String mianji) {
    this.mianji = mianji;
    }
    public String getFangjianshu() {
    return fangjianshu;
    }
    public void setFangjianshu(String fnagjianshu) {
    this.fangjianshu = fnagjianshu;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public String getID() {
    return ID;
    }
    public void setID(String iD) {
    ID = iD;
    }
    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 getEducator() {
    return educator;
    }
    public void setEducator(String educator) {
    this.educator = educator;
    }
    public get(String a,String b,String c,String d,String e,String f,String h,String g,String n) {
    hubie=a;
    zhufang=b;
    mianji=c;
    fangjianshu=d;
    name=e;
    ID=f;
    sex=h;
    nation=g;
    educator=n;
    }
    }

  • 相关阅读:
    node.js 安装后怎么打开 node.js 命令框
    thinkPHP5 where多条件查询
    网站title中的图标
    第一次写博客
    Solution to copy paste not working in Remote Desktop
    The operation could not be completed. (Microsoft.Dynamics.BusinessConnectorNet)
    The package failed to load due to error 0xC0011008
    VS2013常用快捷键
    微软Dynamics AX的三层架构
    怎样在TFS(Team Foundation Server)中链接团队项目
  • 原文地址:https://www.cnblogs.com/lx06/p/14165066.html
Copyright © 2011-2022 走看看