Пример #1
0
 /**
  * Mapear ResulSet a un Pojo
  *
  * @param res
  * @return
  * @throws SQLException
  */
 @Override
 public Estilo mapeo(ResultSet res) throws SQLException {
   Estilo gru = new Estilo();
   gru.setId(res.getInt("id"));
   gru.setNombre(res.getString("nombre"));
   gru.setDescripcion(res.getString("descripcion"));
   gru.setCodigo(res.getString("codigo"));
   return gru;
 }
Пример #2
0
 @Override
 public boolean update(Estilo est) throws SQLException {
   boolean resul = false;
   if (est != null && !est.equals(new Estilo())) {
     DbConnection conn = new DbConnection();
     String sql =
         "UPDATE `estilo` SET `nombre`= ? , `descripcion`= ?, `codigo`= ? WHERE  `id`= ? ;";
     PreparedStatement consulta = conn.getConnection().prepareStatement(sql);
     consulta.setString(1, est.getNombre());
     consulta.setString(2, est.getDescripcion());
     consulta.setString(3, est.getCodigo());
     consulta.setInt(4, est.getId());
     if (consulta.executeUpdate() == 1) {
       resul = true;
     }
     cerrarPeticion(conn, consulta);
   }
   return resul;
 }
Пример #3
0
 @Override
 public int insert(Estilo est) throws SQLException {
   int resul = -1;
   if (est != null && !est.equals(new Estilo())) {
     DbConnection conn = new DbConnection();
     String sql = "INSERT INTO `estilo` (`nombre`,`descripcion`, `codigo` ) VALUES ( ?, ?, ? );";
     PreparedStatement consulta =
         conn.getConnection().prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
     consulta.setString(1, est.getNombre());
     consulta.setString(2, est.getDescripcion());
     consulta.setString(3, est.getCodigo());
     if (consulta.executeUpdate() == 1) {
       ResultSet generatedKeys = consulta.getGeneratedKeys();
       if (generatedKeys.next()) {
         resul = generatedKeys.getInt(1);
         est.setId(resul);
       }
     }
     cerrarPeticion(conn, consulta);
   }
   return resul;
 }