PostulanteDao.java 10.1 KB
Newer Older
1 2 3 4 5 6
package com.roshka.proyectofinal.Postulante;
import com.roshka.proyectofinal.DataBase;
import com.roshka.proyectofinal.entity.Postulante;

import java.sql.Connection;
import java.sql.PreparedStatement;
7 8 9 10
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
11 12

public class PostulanteDao {
13
    List<Postulante> postulante = null;
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

    public static int save(Postulante postulante){
        int status=0;
        try{
            Connection con= DataBase.getConnection();
            PreparedStatement ps=con.prepareStatement(
                    "insert into postulante(nombre,apellido,nro_cedula,correo,telefono,direccion,experiencia_laboral,estudio_universitario,notebook,bootcamp_id,aceptado) values (?,?,?,?,?,?,?,?,?,?,?)");
            ps.setString(1,postulante.getNombre());
            ps.setString(2,postulante.getApellido());
            ps.setInt(3,postulante.getNro_cedula());
            ps.setString(4,postulante.getCorreo());
            ps.setString(5,postulante.getTelefono());
            ps.setString(6,postulante.getDireccion());
            ps.setBoolean(7,postulante.getExpLaboral());
            ps.setBoolean(8,postulante.getEstudioUniversitario());
            ps.setBoolean(9,postulante.getNotebook());
            ps.setInt(10,postulante.getBootcampId());
            ps.setBoolean(11,postulante.getAceptado());
            status=ps.executeUpdate();
            con.close();
        }catch(Exception ex){ex.printStackTrace();}

        return status;
    }
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

    public static List<Postulante> listarPostulante(){
        List<Postulante> postulante = new ArrayList<>();
        String sql = "select a.id, a.nombre, a.apellido, a.nro_cedula, a.correo, a.telefono, a.direccion, " +
                "a.experiencia_laboral, a.estudio_universitario, a.bootcamp_id, a.notebook, c.nombre_lenguaje as bootcamp, \n" +
                "a.aceptado from postulante a\n" +
                "  inner join bootcamp b on b.id= a.bootcamp_id\n" +
                "  inner join lenguaje c on c.id=b.id_lenguaje\n" +
                "  order by a.id;";
        try{
            Connection con= DataBase.getConnection();
            PreparedStatement ps=con.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while(rs.next()){
                Postulante postulanteObject = new Postulante();
                postulanteObject.setId(rs.getInt("id"));
                postulanteObject.setNombre(rs.getString("nombre"));
                postulanteObject.setApellido(rs.getString("apellido"));
                postulanteObject.setNroCedula(rs.getInt("nro_cedula"));
                postulanteObject.setCorreo(rs.getString("correo"));
                postulanteObject.setTelefono(rs.getString("telefono"));
                postulanteObject.setDireccion(rs.getString("direccion"));
                postulanteObject.setExpLaboral(rs.getBoolean("experiencia_laboral"));
                postulanteObject.setEstudioUniversitario(rs.getBoolean("estudio_universitario"));
                postulanteObject.setBootcampId(rs.getInt("bootcamp_id"));
                postulanteObject.setNotebook(rs.getBoolean("notebook"));
                postulanteObject.setNombreBootcamp(rs.getString("bootcamp"));
                postulanteObject.setAceptado(rs.getBoolean("aceptado"));
                postulante.add(postulanteObject);
            }

            con.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return postulante;
    }

    public static void update(int id){
        try{
            Connection con= DataBase.getConnection();
            PreparedStatement ps=con.prepareStatement("update postulante set aceptado= true\n" +
                    "where id=?");
            ps.setInt(1,id);
            ps.executeUpdate();
            con.close();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }

    public static List<Postulante> buscarPorNombre(String nombre){
        List<Postulante> postulante = null;
        Postulante postulanteObject = null;
        try{
            Connection con= DataBase.getConnection();
            PreparedStatement ps=con.prepareStatement("select a.id, a.nombre, a.apellido, a.nro_cedula, a.correo, " +
                    "a.telefono, a.direccion, a.experiencia_laboral, a.estudio_universitario, a.bootcamp_id, a.notebook, " +
                    "c.nombre_lenguaje as bootcamp, \n" + "a.aceptado from postulante a\n" +
                    "  inner join bootcamp b on b.id= a.bootcamp_id\n" +
                    "  inner join lenguaje c on c.id=b.id_lenguaje\n" +
                    "  where a.nombre ilike ? ");
            ps.setString(1, "%" + nombre + "%");
            System.out.println(nombre);
            ResultSet rs = ps.executeQuery();
            postulante = new ArrayList<>();
            postulanteObject= new Postulante();
            while(rs.next()){

                postulanteObject.setId(rs.getInt("id"));
                postulanteObject.setNombre(rs.getString("nombre"));
                postulanteObject.setApellido(rs.getString("apellido"));
Josebaezx committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
                postulanteObject.setNroCedula(rs.getInt("nro_cedula"));
                postulanteObject.setCorreo(rs.getString("correo"));
                postulanteObject.setTelefono(rs.getString("telefono"));
                postulanteObject.setDireccion(rs.getString("direccion"));
                postulanteObject.setExpLaboral(rs.getBoolean("experiencia_laboral"));
                postulanteObject.setEstudioUniversitario(rs.getBoolean("estudio_universitario"));
                postulanteObject.setBootcampId(rs.getInt("bootcamp_id"));
                postulanteObject.setNotebook(rs.getBoolean("notebook"));
                postulanteObject.setNombreBootcamp(rs.getString("bootcamp"));
                postulanteObject.setAceptado(rs.getBoolean("aceptado"));
                postulante.add(postulanteObject);
            }
            con.close();
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return postulante;
    }

    public static List<Postulante> listarPostulanteAceptados(){
        List<Postulante> postulante = null;
        try{
            Connection con= DataBase.getConnection();
            PreparedStatement ps=con.prepareStatement("select a.id, a.nombre, a.apellido, a.nro_cedula, a.correo, " +
                    "a.telefono, a.direccion, a.experiencia_laboral, a.estudio_universitario, a.bootcamp_id, a.notebook, " +
                    "c.nombre_lenguaje as bootcamp, \n" + "a.aceptado from postulante a\n" +
                    "  inner join bootcamp b on b.id= a.bootcamp_id\n" +
                    "  inner join lenguaje c on c.id=b.id_lenguaje\n" +
                    "  where a.aceptado= true ");
            ResultSet rs = ps.executeQuery();
            postulante = new ArrayList<>();
            Postulante postulanteObject= new Postulante();
            while(rs.next()){
                postulanteObject.setId(rs.getInt("id"));
                postulanteObject.setNombre(rs.getString("nombre"));
                postulanteObject.setApellido(rs.getString("apellido"));
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
                postulanteObject.setNroCedula(rs.getInt("nro_cedula"));
                postulanteObject.setCorreo(rs.getString("correo"));
                postulanteObject.setTelefono(rs.getString("telefono"));
                postulanteObject.setDireccion(rs.getString("direccion"));
                postulanteObject.setExpLaboral(rs.getBoolean("experiencia_laboral"));
                postulanteObject.setEstudioUniversitario(rs.getBoolean("estudio_universitario"));
                postulanteObject.setBootcampId(rs.getInt("bootcamp_id"));
                postulanteObject.setNotebook(rs.getBoolean("notebook"));
                postulanteObject.setNombreBootcamp(rs.getString("bootcamp"));
                postulanteObject.setAceptado(rs.getBoolean("aceptado"));
                postulante.add(postulanteObject);
            }
            con.close();
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return postulante;
    }

    public static List<Postulante> listarPorBootcamp(String nombre){
        List<Postulante> postulante = null;
        try{
            Connection con= DataBase.getConnection();
            PreparedStatement ps=con.prepareStatement("select a.id, a.nombre, a.apellido, a.nro_cedula, a.correo, a.telefono, a.direccion, \n" +
                    "                a.experiencia_laboral, a.estudio_universitario, a.bootcamp_id, a.notebook, c.nombre_lenguaje as bootcamp, \n" +
                    "                a.aceptado from postulante a\n" +
                    "                inner join bootcamp b on b.id= a.bootcamp_id\n" +
                    "                inner join lenguaje c on c.id=b.id_lenguaje\n" +
                    "                where c.nombre_lenguaje ilike ? ");
            ps.setString(1, "%" + nombre + "%");
            ResultSet rs = ps.executeQuery();
            postulante = new ArrayList<>();
            Postulante postulanteObject= new Postulante();
            while(rs.next()){
                postulanteObject.setId(rs.getInt("id"));
                postulanteObject.setNombre(rs.getString("nombre"));
                postulanteObject.setApellido(rs.getString("apellido"));
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
                postulanteObject.setNroCedula(rs.getInt("nro_cedula"));
                postulanteObject.setCorreo(rs.getString("correo"));
                postulanteObject.setTelefono(rs.getString("telefono"));
                postulanteObject.setDireccion(rs.getString("direccion"));
                postulanteObject.setExpLaboral(rs.getBoolean("experiencia_laboral"));
                postulanteObject.setEstudioUniversitario(rs.getBoolean("estudio_universitario"));
                postulanteObject.setBootcampId(rs.getInt("bootcamp_id"));
                postulanteObject.setNotebook(rs.getBoolean("notebook"));
                postulanteObject.setNombreBootcamp(rs.getString("bootcamp"));
                postulanteObject.setAceptado(rs.getBoolean("aceptado"));
                postulante.add(postulanteObject);
            }
            con.close();
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return postulante;
    }
201
}