Beispiel #1
0
  public void inserir(Rodovia rodovia) throws ClassNotFoundException {

    System.out.println("entrou no dao");

    String sql =
        "Insert into RODOVIA"
            + " (NOME, EXTENSAOKM, CIDADEINICIAL, UFINICIAL, CIDADEFINAL, UFFINAL)"
            + " VALUES (?,?,?,?,?,?)";

    try {
      PreparedStatement stmt = con.prepareStatement(sql);
      // stmt.setInt(1, rodovia.getIdRodovia());
      stmt.setString(1, rodovia.getNome());
      stmt.setFloat(2, rodovia.getExtensaoKm());
      stmt.setString(3, rodovia.getCidadeInicial());
      stmt.setString(4, rodovia.getUfInicial());
      stmt.setString(5, rodovia.getCidadeFinal());
      stmt.setString(6, rodovia.getUfFinal());
      // stmt.setInt(8, rodovia.getSituacao().charAt(0));

      stmt.executeUpdate();
      stmt.close();
      con.close();

      // SQL Server

      stmt = conS.prepareStatement(sql);
      // stmt.setInt(1, rodovia.getIdRodovia());
      stmt.setString(1, rodovia.getNome());
      stmt.setFloat(2, rodovia.getExtensaoKm());
      stmt.setString(3, rodovia.getCidadeInicial());
      stmt.setString(4, rodovia.getUfInicial());
      stmt.setString(5, rodovia.getCidadeFinal());
      stmt.setString(6, rodovia.getUfFinal());
      // stmt.setInt(8, rodovia.getSituacao().charAt(0));

      stmt.executeUpdate();
      stmt.close();
      conS.close();
    } catch (SQLException e) {
      throw new RuntimeException(e + "Erro na Conexão");
    }
  }
Beispiel #2
0
  public void alterar(Rodovia rodovia) throws ClassNotFoundException {

    String sql =
        "update RODOVIA set"
            + " NOME = ?, EXTENSAOKM = ?, CIDADEINICIAL = ?, UFINICIAL = ?, CIDADEFINAL = ?, UFFINAL = ?"
            + " where IDRODOVIA = ?";

    try {
      PreparedStatement stmt = con.prepareStatement(sql);

      stmt.setString(1, rodovia.getNome());
      stmt.setFloat(2, rodovia.getExtensaoKm());
      stmt.setString(3, rodovia.getCidadeInicial());
      stmt.setString(4, rodovia.getUfInicial());
      stmt.setString(5, rodovia.getCidadeFinal());
      stmt.setString(6, rodovia.getUfFinal());
      // stmt.setInt(7, rodovia.getSituacao());
      stmt.setInt(7, rodovia.getIdRodovia());

      stmt.executeUpdate();
      stmt.close();
      con.close();

      // SQO Server
      /*
      stmt = conS.prepareStatement(sql);

      stmt.setString(1, rodovia.getNome());
      stmt.setFloat(2, rodovia.getExtensaoKm());
      stmt.setString(3, rodovia.getCidadeInicial());
      stmt.setString(4, rodovia.getUfInicial());
      stmt.setString(5, rodovia.getCidadeFinal());
      stmt.setString(6, rodovia.getUfFinal());
      stmt.setInt(7, rodovia.getSituacao().charAt(0));
      stmt.setInt(8, rodovia.getIdRodovia());

      stmt.executeUpdate();
      stmt.close();
      conS.close();*/
    } catch (SQLException e) {
      throw new RuntimeException(e + "Erro na Conexão");
    }
  }