zoukankan      html  css  js  c++  java
  • JAVA操作数据库的增删改查

    package com.oracle.dao;
    
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    
    import java.util.LinkedList;
    
    import com.oracle.model.Emp;
    
    public class EmpDao {
         public int add(Connection conn,Emp emp) throws Exception{
             String sql="insert into emp values(?,?,?,?,?,?,?,?)";
             PreparedStatement pst=conn.prepareStatement(sql);
             pst.setInt(1, emp.getEmpno());
             pst.setString(2, emp.getEname());
             pst.setString(3, emp.getJob());
             pst.setInt(4, emp.getMgr());
             pst.setString(5, emp.getHiredate());
             pst.setDouble(6, emp.getSal());
             pst.setDouble(7,emp.getComm());
             pst.setInt(8, emp.getDeptno());
             return pst.executeUpdate();
         }
         public int modify(Connection conn,Emp emp) throws Exception{
             String sql ="Update emp set empno=?,ename=?,job=?,mgr=?,hiredate=?,sal=?,comm=?,deptno=?";
             PreparedStatement pst = conn.prepareStatement(sql);
             pst.setInt(1, emp.getEmpno());
             pst.setString(2, emp.getEname());
             pst.setString(3, emp.getJob());
             pst.setInt(4, emp.getMgr());
             pst.setString(5, emp.getHiredate());
             pst.setDouble(6, emp.getSal());
             pst.setDouble(7,emp.getComm());
             pst.setInt(8, emp.getDeptno());
             return pst.executeUpdate();
         }
         public int del(Connection conn,Emp emp) throws Exception{
             String sql="delete from emp where empno=?";
             PreparedStatement pst = conn.prepareStatement(sql);
             pst.setInt(1, emp.getDeptno());
             return pst.executeUpdate();
         }
         public LinkedList<Emp> findAll(Connection conn) throws Exception{
             String sql="select empno,ename,job,mgr,hiredate,sal,comm,deptno from emp";
             PreparedStatement pst =conn.prepareStatement(sql);
             ResultSet rs=pst.executeQuery();
             LinkedList<Emp> arr=new LinkedList<Emp>();
             while(rs.next()) {
                 Emp emp = new Emp();
                 emp.setEmpno(rs.getInt("empno"));
                 emp.setEname(rs.getString("ename"));
                 emp.setJob(rs.getString("job"));
                 emp.setMgr(rs.getInt("mgr"));
                 emp.setHiredate(rs.getString("hiredate"));
                 emp.setSal(rs.getDouble("sal"));
                 emp.setComm(rs.getDouble("comm"));
                 emp.setDeptno(rs.getInt("deptno"));
                 arr.add(emp);
                 
                 
             }
            return arr;         
         }
    }
  • 相关阅读:
    xftp,winscp显示隐藏文件
    今日校园-打卡
    dungeon quest(又名暗黑遗迹,勇闯地下城等)装备体系简述
    frp转发
    虚拟机win10添加新磁盘
    JEECG(一) 如何配置自己的业务包
    C# 获取Url 请求方式 域名 端口 路径
    js url 参数 转换成 json 对象数据
    VisualStudio2017 远程 调试 IIS 服务器 web网站
    c# MVC Action 如何知道 发送方给你的 Json 数据的格式内容是什么
  • 原文地址:https://www.cnblogs.com/wangyufei123/p/8043619.html
Copyright © 2011-2022 走看看