primero
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package aadd.palomafp.anp.dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import aadd.palomafp.anp.conexion.ConexionDB;
|
||||
import aadd.palomafp.anp.conexion.ConfigConexion;
|
||||
import aadd.palomafp.anp.dao.FamiliaProfesionalDAO;
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
import aadd.palomafp.anp.model.FamiliaProfesional;
|
||||
|
||||
|
||||
public class FamiliaProfesionalDAOImpl implements FamiliaProfesionalDAO {
|
||||
|
||||
@Override
|
||||
public void insert(FamiliaProfesional fa) throws FormationException {
|
||||
String sql = ConfigConexion.get("sql.familia.insert");
|
||||
try (Connection con = ConexionDB.getConexion();
|
||||
PreparedStatement ps = con.prepareStatement(sql)) {
|
||||
|
||||
ps.setString(1, fa.getCodigo());
|
||||
ps.setString(2, fa.getNombre());
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
throw new FormationException(
|
||||
"Error al consultar la familia " + fa.getCodigo() + ": " + e.getMessage(), e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(FamiliaProfesional fa) throws FormationException {
|
||||
String sql = ConfigConexion.get("sql.familia.update");
|
||||
try (Connection con = ConexionDB.getConexion();
|
||||
PreparedStatement ps = con.prepareStatement(sql)) {
|
||||
ps.setString(1, fa.getNombre());
|
||||
ps.setString(2, fa.getCodigo());
|
||||
|
||||
return ps.executeUpdate() > 0;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
throw new FormationException(
|
||||
"Error al consultar la familia " + fa.getCodigo() + ": " + e.getMessage(), e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FamiliaProfesional findById(String codigo) throws FormationException {
|
||||
String sql = ConfigConexion.get("sql.familia.porId");
|
||||
try (Connection con = ConexionDB.getConexion();
|
||||
PreparedStatement ps = con.prepareStatement(sql)) {
|
||||
|
||||
ps.setString(1, codigo);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new FamiliaProfesional(rs.getString("codigo"), rs.getString("nombre"));
|
||||
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
throw new FormationException(
|
||||
"Error al consultar la familia "+ codigo + ": " + e.getMessage(), e
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user