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

📄 mydao.java

📁 JSP通讯录程序(适合初学者研究),JSP通讯录程序(适合初学者研究)
💻 JAVA
字号:
package Dao;
import java.sql.*;
import java.util.*;
import Bean.*;
import ConnectionManager.*;

public class mydao {

    private Connection conn = null;
    private PreparedStatement pstmt = null;
    private ResultSet rs = null;
    public Vector getAllDatas(String sql){
        Vector datas = new Vector();
        try{
            conn = ConnectionManagerMyAddrBook.getCon();
            pstmt=conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            while(rs.next()){
                MyAddrBookBean bean = new MyAddrBookBean();
                bean.setID(rs.getInt(1));
                bean.setFirstName(rs.getString(2));
                bean.setLastName(rs.getString(3));
                bean.setJobTitle(rs.getString(4));
                bean.setDepartMent(rs.getString(5));
                bean.setOffPh(rs.getString(6));
                bean.setMobile(rs.getString(7));
                bean.setEmail(rs.getString(8));
                datas.add(bean);
            }
        }catch(Exception ex){
            ex.printStackTrace();
        }finally{
            closeAll();
        }
        return datas;
    }
    public  int Insert(MyAddrBookBean mb)
    {
      int num =0;
      try{
          conn = ConnectionManagerMyAddrBook.getCon();
           String sql = "insert into MyAddrBook values(?,?,?,?,?,?,?)";
           pstmt = conn.prepareStatement(sql);
          // rs = pstmt.executeQuery();
           pstmt.setString(1, mb.getFirstName());
           pstmt.setString(2, mb.getLastName());
           pstmt.setString(3, mb.getJobTitle());
           pstmt.setString(4, mb.getDepartMent());
           pstmt.setString(5, mb.getOffPh());
           pstmt.setString(6, mb.getMobile());
           pstmt.setString(7, mb.getEmail());
           num= pstmt.executeUpdate();
       }catch(Exception ex){
          ex.printStackTrace();
      }finally{
          closeAll();
      }
      return num;
    }
     public int update(String sql,MyAddrBookBean mb){
         int num = 0;
         try {
             conn = ConnectionManagerMyAddrBook.getCon();
             pstmt = conn.prepareStatement(sql);
             pstmt.setString(1, mb.getFirstName());
             pstmt.setString(2, mb.getLastName());
             pstmt.setString(3, mb.getJobTitle());
             pstmt.setString(4, mb.getDepartMent());
             pstmt.setString(5, mb.getOffPh());
             pstmt.setString(6, mb.getMobile());
             pstmt.setString(7, mb.getEmail());
             num = pstmt.executeUpdate();
         } catch (SQLException ex) {
             ex.printStackTrace();
         }
         finally{
          closeAll();
      }
      return num;
 }
    public int delUser(int uid){
        int res = 0;
        try{
            conn = ConnectionManagerMyAddrBook.getCon();
            String sql = "delete from MyAddrBook where ID=?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1,uid);
            res = pstmt.executeUpdate();
        }catch(Exception ex){
            ex.printStackTrace();
        }finally{
            closeAll();
        }
        return res;
    }

    public void closeAll(){
        try{
           if(rs!=null)rs.close();
           if(pstmt!=null)pstmt.close();
           if(conn!=null)conn.close();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
    }


}

⌨️ 快捷键说明

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