ImageVerifierCode 换一换
格式:DOCX , 页数:22 ,大小:18.42KB ,
资源ID:9379577      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9379577.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(web用户管理系统源代码.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

web用户管理系统源代码.docx

1、web用户管理系统源代码/连接数据库代码package com.tools;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;public class DBUtil public static Connection getConnection() throws ClassNotFoundException, SQLException / 1. 导入Jar包 / 2. 加载驱动 Class.forName(oracle.jdbc.driver.OracleDriver); /

2、 3. 获得数据库连接 Connection conn = DriverManager.getConnection(jdbc:oracle:thin:localhost:1521:orcl, scott, tiger); return conn; /EMP表的增删改查功能实现package com.dao;import java.sql.Connection;import java.sql.Date;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import ja

3、va.sql.Statement;import java.text.SimpleDateFormat;import java.util.ArrayList;import com.bean.Emp;import com.tools.DBUtil;public class EmpDAO public static void main(String args) throws ClassNotFoundException, SQLException EmpDAO dao = new EmpDAO(); dao.queryAll(); public ArrayList queryAll() throws

4、 ClassNotFoundException, SQLException Connection conn = DBUtil.getConnection(); / 4. 创建Statement Statement s = conn.createStatement(); / 5. 执行SQL语句 String sql = select * from emp; / 6. 处理结果集 ResultSet rs = s.executeQuery(sql); ArrayList list = new ArrayList(); while (rs.next() Emp e = new Emp(); e.s

5、etEmpno(rs.getInt(empno); e.setEname(rs.getString(ename); e.setJob(rs.getString(job); e.setManager(rs.getInt(mgr); e.setSal(rs.getFloat(sal); e.setComm(rs.getFloat(comm); Date date = rs.getDate(hiredate); e.setHiredate(date.getYear() + 1900 + 年 + (date.getMonth() + 1) + 月 + date.getDate() + 日); e.se

6、tDeptno(rs.getInt(deptno); list.add(e); / 7. 关闭 rs.close(); s.close(); conn.close(); return list; public Emp findById(int id) throws ClassNotFoundException, SQLException Connection conn = DBUtil.getConnection(); / SQL语句生成 String sql = select * from emp where empno=?; PreparedStatement ps = conn.prep

7、areStatement(sql); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); Emp e = new Emp(); if (rs.next() e.setEmpno(rs.getInt(empno); e.setEname(rs.getString(ename); e.setJob(rs.getString(job); e.setManager(rs.getInt(mgr); e.setSal(rs.getFloat(sal); e.setComm(rs.getFloat(comm); Date d = rs.getDate(hi

8、redate); java.util.Date dd = new java.util.Date(d.getTime(); String str = dd.getYear() + 1900 + - + (dd.getMonth() + 1) + - + dd.getDate(); e.setHiredate(str); e.setDeptno(rs.getInt(deptno); / 7. 关闭 rs.close(); ps.close(); conn.close(); return e; public void deleteById(int id) throws ClassNotFoundEx

9、ception, SQLException Connection conn = DBUtil.getConnection(); String sql = delete from emp where empno=?; PreparedStatement ps = conn.prepareStatement(sql); ps.setInt(1, id); ps.executeUpdate(); / 7. 关闭 ps.close(); conn.close(); public void add(Emp e) throws ClassNotFoundException, SQLException Co

10、nnection conn = DBUtil.getConnection(); String sql = insert into emp ( + empno, + / 员工编号 ename, + job, + mgr, + sal, + comm, + hiredate, + deptno) + values (SEQ_EMP_EMPNO.nextval, ?, ?, ?, ?, ?, to_date(?, YYYY-MM-DD), ?); PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, e.getEname

11、(); ps.setString(2, e.getJob(); ps.setInt(3, e.getManager(); ps.setFloat(4, e.getSal(); ps.setFloat(5, e.getComm(); ps.setString(6, e.getHiredate(); ps.setInt(7, e.getDeptno(); ps.executeUpdate(); / 7. 关闭 ps.close(); conn.close(); public void update(Emp e) throws ClassNotFoundException, SQLException

12、 Connection conn = DBUtil.getConnection(); String sql = update emp set ename=?, job=?, mgr=?, sal=?, comm=?, hiredate=to_date(?, YYYY-MM-DD), deptno=? where empno=?; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, e.getEname(); ps.setString(2, e.getJob(); ps.setInt(3, e.getManager

13、(); ps.setFloat(4, e.getSal(); ps.setFloat(5, e.getComm(); ps.setString(6, e.getHiredate(); ps.setInt(7, e.getDeptno(); ps.setInt(8, e.getEmpno(); ps.executeUpdate(); / 7. 关闭 ps.close(); conn.close(); /EMP表的各种数据成员package com.bean;public class Emp private int empno; private String ename; private Stri

14、ng job; private int manager; private float sal; private float comm; private int deptno; private String hiredate; public int getEmpno() return empno; public void setEmpno(int empno) this.empno = empno; public String getEname() return ename; public void setEname(String ename) this.ename = ename; publi

15、c String getJob() return job; public void setJob(String job) this.job = job; public int getManager() return manager; public void setManager(int manager) this.manager = manager; public float getSal() return sal; public void setSal(float sal) this.sal = sal; public float getComm() return comm; public

16、void setComm(float comm) m = comm; public int getDeptno() return deptno; public void setDeptno(int deptno) this.deptno = deptno; public String getHiredate() return hiredate; public void setHiredate(String hiredate) this.hiredate = hiredate; /增加用户信息package com;import java.io.IOException;import java.s

17、ql.SQLException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.bean.Emp;import com.dao.EmpDAO;public class AddEmp extends HttpServlet /* * Constructor of the object. */

18、public AddEmp() super(); /* * Destruction of the servlet. */ public void destroy() super.destroy(); / Just puts destroy string in log / Put your code here /* * The doGet method of the servlet. * * This method is called when a form has its tag value method equals to get. * * param request the request

19、 send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOExceptio

20、n / 获得参数 String ename = request.getParameter(ename); String job = request.getParameter(job); String mgr = request.getParameter(mgr); String sal = request.getParameter(sal); String comm = request.getParameter(comm); String hiredate = request.getParameter(hiredate); String deptno = request.getParamete

21、r(deptno); Emp emp = new Emp(); emp.setEname(ename); emp.setJob(job); emp.setManager(Integer.parseInt(mgr); emp.setSal(Float.parseFloat(sal); emp.setComm(Float.parseFloat(comm); emp.setHiredate(hiredate); emp.setDeptno(Integer.parseInt(deptno); / 调用查询 EmpDAO dao = new EmpDAO(); try dao.add(emp); cat

22、ch (NumberFormatException e) / TODO Auto-generated catch block e.printStackTrace(); catch (ClassNotFoundException e) / TODO Auto-generated catch block e.printStackTrace(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); / 设置参数 / 重定向 response.sendRedirect(ListEmp); /* *

23、The doPost method of the servlet. * * This method is called when a form has its tag value method equals to post. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOExc

24、eption if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doGet(request, response); /* * Initialization of the servlet. * * throws ServletException if an error occurs */ public void init() throws ServletException

25、/ Put your code here /删除信息package com;import java.io.IOException;import java.io.PrintWriter;import java.sql.SQLException;import javax.servlet.RequestDispatcher;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servle

26、t.http.HttpServletResponse;import com.bean.Emp;import com.dao.EmpDAO;public class DeleteEmp extends HttpServlet /* * Constructor of the object. */ public DeleteEmp() super(); /* * Destruction of the servlet. */ public void destroy() super.destroy(); / Just puts destroy string in log / Put your code

27、here /* * The doGet method of the servlet. * * This method is called when a form has its tag value method equals to get. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * thro

28、ws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException / 获得参数 String empno = request.getParameter(empno); / 调用查询 EmpDAO dao = new EmpDAO(); try dao.deleteById(Integer.parseInt(empno); catch (NumberFormatException e) / TODO Auto-generated catch block e.printStackTrace(); catch (ClassNotFoundException e) / TODO Auto-generated catch block e.printStackTrace(); catch (SQLException e) / TODO Auto-generated catch block

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1