holderdao.java~10~

来自「这是java编写宠物医院项目」· JAVA~10~ 代码 · 共 207 行

JAVA~10~
207
字号
 package bholder;
 import java.sql.*;
 import java.util.*;
 import jdbc.*;

public class HolderDAO {
    public HolderDAO() {
    }
    public Collection holde_select(){
        ArrayList al =new ArrayList(10);
        try{
            Statement stmt=JDBC.getConnection().createStatement();
            ResultSet rs=stmt.executeQuery("select * from holder_info");
            while(rs.next()){
                HolderVO hvo = new HolderVO();
                hvo.setId(rs.getInt(1));
                hvo.setName(rs.getString(2));
                hvo.setSex(rs.getString(3));
                hvo.setAge(rs.getInt(4));
                hvo.setAddress(rs.getString(5));
                hvo.setTime(rs.getString(6));
                al.add(hvo);
            }
            rs.close();
            stmt.close();
        }catch(SQLException ex){
            ex.printStackTrace();
        }
        return al;
    }

    public Collection holder_name(String name){
           Collection caseNameList = null;
           Statement stat = null;
           ResultSet rs = null;
           try {
               String sql = "select * from holder_info where holdername like'%" + name +"%'";
               stat = JDBC.getConnection().createStatement();
               rs = stat.executeQuery(sql);
               if(rs.next()){
                   caseNameList = new ArrayList();
                   do{
                       HolderVO vo = new HolderVO();
                       vo.setId(rs.getInt(1));
                       vo.setName(rs.getString(2));
                       vo.setSex(rs.getString(3));
                       vo.setAge(rs.getInt(4));
                       vo.setAddress(rs.getString(5));
                       vo.setTime(rs.getString(6));
                       caseNameList.add(vo);
                   }while(rs.next());
               }
           } catch (SQLException ex) {
               ex.printStackTrace();
           }
           finally{
               if(rs != null){
                   try {
                       rs.close();
                   } catch (SQLException ex1) {
                   }
                   rs = null;
               }
               if(stat != null){
                   try {
                       stat.close();
                   } catch (SQLException ex2) {
                   }
                   stat = null;
               }
           }
           return caseNameList;
       }
//
//    public Map holder_name(String name ){
//        HolderVO vo=null;
//        Statement stmt=null;
//        ResultSet rs=null;
//        Map map=null;
//        try{
//            stmt=JDBC.getConnection().createStatement();
//            String sql ="select * from holder_info where holdername like'%" + name +"%'";
//            rs=stmt.executeQuery(sql);
//            if(rs.next()){
//                map=new HashMap();
//                do{
//                    vo = new HolderVO();
//                    //                vo = new HolderVO();
//                vo.setId(rs.getInt(1));
//                vo.setName(rs.getString(2));
//                vo.setSex(rs.getString(3));
//                vo.setAge(rs.getInt(4));
//                vo.setAddress(rs.getString(5));
//                vo.setTime(rs.getString(6));
//                    map.put(rs.getObject(1),vo);
//                }while(rs.next());
//            }
//        }catch(SQLException ex){
//            ex.printStackTrace();
//        }finally{
//            if(rs!=null){
//                try{
//                    rs.close();
//                }catch(SQLException ex){
//                }
//                rs=null;
//            }
//            if(stmt!=null){
//                try{
//                    stmt.close();
//                }catch(SQLException ex2){
//                }
//                stmt=null;
//            }
//        }
//        return map;
//    }

//  //按姓名查询,但每次只能查询出一条信息
//    public HolderVO holder_name(String name){
//        HolderVO vo = null;
//        Statement stmt = null;
//        ResultSet rs = null;
//        try {
//            stmt = JDBC.getConnection().createStatement();
//            String sql = "select * from holder_info where holdername like'%" + name +"%'";
//            rs = stmt.executeQuery(sql);
//            if (rs.next()) {
//                vo = new HolderVO();
//                vo.setId(rs.getInt(1));
//                vo.setName(rs.getString(2));
//                vo.setSex(rs.getString(3));
//                vo.setAge(rs.getInt(4));
//                vo.setAddress(rs.getString(5));
//                vo.setTime(rs.getString(6));
//            }
//        } catch (SQLException ex) {
//            ex.printStackTrace();
//        } finally {
//            if (rs != null) {
//                try {
//                    rs.close();
//                } catch (SQLException ex1) {
//                }
//                rs = null;
//            }
//            if (stmt != null) {
//                try {
//                    stmt.close();
//                } catch (SQLException ex2) {
//                }
//                stmt = null;
//            }
//        }
//        return vo;
//    }

//    public Map holde_select() {
//        Map map = null;
//        Statement stmt = null;
//        ResultSet rs = null;
//        try{
//            stmt = JDBC.getConnection().createStatement();
//            rs = stmt.executeQuery("select * from Holder_info");
//            if (rs.next()){
//                map = new HashMap();
//                do{
//                    HolderVO hvo=new HolderVO();
//                    hvo.setId(rs.getInt(1));
//                    hvo.setName(rs.getString(2));
//                    hvo.setSex(rs.getString(3));
//                    hvo.setAge(rs.getInt(4));
//                    hvo.setAddress(rs.getString(5));
//                    hvo.setTime(rs.getString(6));
//                    map.put(rs.getObject(1),hvo);
//                }while(rs.next());
//            }
//        }catch(SQLException ex){
//            ex.printStackTrace();
//        }finally{
//            if(stmt!=null){
//                try{
//                    stmt.close();
//                }catch(SQLException ex1){
//                }
//            }
//            if(rs!=null){
//                try{
//                    rs.close();
//                }catch(SQLException ex2){
//                }
//            }
//        }
//        return map;
//    }
    public static void main(String[] args){
        System.out.println("sdfgdfsgdfg.........");
        HolderDAO dao=new HolderDAO();
        //HolderVO vo=dao.holder_name("");
      // if(vo!=null)
        //System.out.println(vo.getAddress());

    }

}

⌨️ 快捷键说明

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