⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dboper.java

📁 java实现管理系统 可以对公司人员进行管理
💻 JAVA
字号:
package cn.com.edu.gui.model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import cn.com.edu.*;
import cn.com.edu.gui.contral.UserLog;


public class DbOper implements DBOperImpl{
  public Vector getData() throws DBException{
    Connection con = DBConnection.getConnect(DBConnection.getProperties(),"oracle");
    Vector v = new Vector();
    Statement stmt  = null;
    try{
      stmt= con.createStatement();
      ResultSet set = stmt.executeQuery("select * from test_emp");
      while(set.next()){
        
        String name = set.getString(1);
        String password = set.getString(2);
        v.addElement(new UserLog(name,password));
      }
      if(v.size() == 0){
        throw new DBException("数据库中没有记录");
      }
    } catch(SQLException ex){
      System.out.println();
    } finally{
      if(con != null){
        con = null;
      }
      if(stmt != null){
        stmt = null;
      }
    }
    return v;
  }
  public boolean addUserInfo(UserLog ul){
    boolean flag = false;
    DBConnectionManager db = DBConnectionManager.getInstance();
    Connection con = db.getConnection("oracle");
    PreparedStatement pstmt = null;
    try{
      pstmt = con.prepareStatement("insert into Logic values(?,?)");
      pstmt.setString(1,ul.getName());
      pstmt.setString(2,ul.getPassword());
     
      int count = pstmt.executeUpdate();
      
      if(count != 0){
        flag = true;
      }
    }catch(Exception e){
      
    } finally{
      if(con != null){
        con = null;
      }
      if(pstmt != null){
        pstmt = null;
      }
    } 
    return flag;
    
  }
  public Vector getDept_name(){
    Vector v = new Vector();
    DBConnectionManager db = DBConnectionManager.getInstance();
    Connection con = db.getConnection("oracle");
    Statement stmt = null;
    try{
      stmt = con.createStatement();
      ResultSet set = stmt.executeQuery("select department_name from departments_11");
      while(set.next()){
        String dept_name = set.getString("department_name");
        v.addElement(dept_name);
        System.out.println(dept_name);
      }
    }catch(Exception e){
      
    }
    return v;
  }
 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -