PostulanteDao.java 13.7 KB
Newer Older
1 2 3 4 5
package com.roshka.proyectofinal.Postulante;
import com.roshka.proyectofinal.DataBase;
import com.roshka.proyectofinal.entity.Postulante;
import java.sql.Connection;
import java.sql.PreparedStatement;
6
import java.sql.ResultSet;
7 8 9
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
10

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
    public class PostulanteDao {
        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();
33 34
            }

35
            return status;
36 37
        }

38 39 40 41 42
        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" +
43 44
                    "  inner join bootcamp b on b.id= a.bootcamp_id\n" +
                    "  inner join lenguaje c on c.id=b.id_lenguaje\n" +
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
                    "  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;
        }
74

Jose Baez committed
75 76 77
        public static void update(int id, String valor) {
            String v = valor;
            if (v == "1") {
78 79
                try {
                    Connection con = DataBase.getConnection();
Jose Baez committed
80
                    PreparedStatement ps = con.prepareStatement("update postulante set aceptado= false " +
81 82 83 84
                            "where id=?");
                    ps.setInt(1, id);
                    ps.executeUpdate();
                    con.close();
Jose Baez committed
85 86
                }
                catch (Exception ex) {
87 88 89 90 91
                    ex.printStackTrace();
                }
            } else {
                try {
                    Connection con = DataBase.getConnection();
Jose Baez committed
92 93
                    PreparedStatement ps = con.prepareStatement("update postulante set aceptado= true " +
                            " where id=?");
94 95 96 97 98 99
                    ps.setInt(1, id);
                    ps.executeUpdate();
                    con.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
Josebaezx committed
100
            }
101

Jose Baez committed
102

Josebaezx committed
103 104
        }

105 106 107 108 109 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
        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"));
                    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();
141
            }
142
            return postulante;
143 144
        }

145 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
        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"));
                    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();
177
            }
178
            return postulante;
179 180
        }

181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
        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"));
                    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;
        }
217

218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
        public static List<Postulante> buscarPorNoteBook() {
            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.notebook=true ");
                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"));
                    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();
252
            }
253
            return postulante;
254 255
        }
    }
256

257