Ejemplo n.º 1
0
  public void update(Publicacao pu) throws Exception {

    String sql =
        "UPDATE publicacao SET "
            + "id_anais = ?, "
            + "nome_publicacao = ?, "
            + "tipo_publicacao = ?, "
            + "tema_publicacao = ?, "
            + "area_publicacao = ?, "
            + "resumo_publicacao = ?, "
            + "link_publicacao = ? WHERE id_publicacao = ?";

    Connection conn = ConnectionFactory.getConnection();

    PreparedStatement stmt = conn.prepareStatement(sql);

    if (pu.getAnais() == null) {
      stmt.setString(1, null);
    } else {
      stmt.setInt(1, pu.getAnais().getId());
    }
    stmt.setString(2, pu.getNome());
    stmt.setString(3, pu.getTipo());
    stmt.setString(4, pu.getTema());
    stmt.setString(5, pu.getArea());
    stmt.setString(6, pu.getResumo());
    stmt.setString(7, pu.getLink());
    stmt.setInt(8, pu.getId());
    stmt.execute();
    stmt.close();
  }
Ejemplo n.º 2
0
  public void save(Publicacao pu) throws Exception {

    String sql =
        "INSERT INTO publicacao (id_anais, nome_publicacao, tipo_publicacao, tema_publicacao, area_publicacao, "
            + "resumo_publicacao, link_publicacao, data_hora_cadastro) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";

    Connection conn = ConnectionFactory.getConnection();

    PreparedStatement stmt = conn.prepareStatement(sql);

    if (pu.getAnais() == null) {
      stmt.setString(1, null);
    } else {
      stmt.setInt(1, pu.getAnais().getId());
    }
    stmt.setString(2, pu.getNome());
    stmt.setString(3, pu.getTipo());
    stmt.setString(4, pu.getTema());
    stmt.setString(5, pu.getArea());
    stmt.setString(6, pu.getResumo());
    stmt.setString(7, pu.getLink());

    Date data = new Date(System.currentTimeMillis());
    SimpleDateFormat formatarDate = new SimpleDateFormat("yyyy-MM-dd");
    stmt.setString(8, formatarDate.format(data));

    stmt.execute();
    stmt.close();

    conn.close();
  }