web用户管理系统php,web用户管理系统源代码

41528d3028836879cd698677c3999917.gifweb用户管理系统源代码

//连接数据库代码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“);// 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 java.sql.Statement;import java.text.SimpleDateat;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 ClassNotFoundException,SQLException {Connection conn = DBUtil.getConnection();// 4. 创建 StatementStatement s = conn.createStatement();// 5. 执行 SQL 语句String sql = “select * from emp“;// 6. 处理结果集ResultSet rs = s.cuteQuery(sql);ArrayList list = new ArrayList();while (rs.next()) {Emp e = new Emp();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 date = rs.getDate(“hiredate“);e.setHiredate(date.getYear() + 1900 + “年“ + (date.getMonth() + 1) + “月“ + date.getDate() + “日“);e.setDeptno(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.prepareStatement(sql);ps.setInt(1, id);ResultSet rs = ps.cuteQuery();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(“hiredate“);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 ClassNotFoundException, SQLException {Connection conn = DBUtil.getConnection();String sql = “delete from emp where empno=?“;PreparedStatement ps = conn.prepareStatement(sql);ps.setInt(1, id);ps.cuteUpdate();// 7. 关闭ps.close();conn.close();}public void add(Emp e) throws ClassNotFoundException, SQLException {Connection 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值