コード例 #1
0
  public ArrayList<Orientacao> getBy(String SQL) {

    Connection conn = new Conn().getConnection();
    ArrayList<Orientacao> lo = new ArrayList<Orientacao>();

    try {
      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery(SQL);

      Orientacao o = new Orientacao();
      while (rs.next()) {
        o.setAluno_id(rs.getInt("aluno_id"));
        o.setProfessor_id(rs.getInt("professor_id"));
        o.setAno(rs.getInt("ano"));
        lo.add(o);
      }

      rs.last();

    } catch (SQLException e) {
      System.out.println("Erro no SQL");
    }

    return lo;
  }
コード例 #2
0
  public boolean Add(Orientacao o) {
    String SQL;

    SQL =
        "INSERT INTO orientacao (aluno_id, professor_id, ano)"
            + "VALUES"
            + " ("
            + o.getAluno_id()
            + ", "
            + o.getProfessor_id()
            + ", "
            + o.getAno()
            + ")";

    Connection conn = new Conn().getConnection();

    try {
      Statement stmt = conn.createStatement();
      stmt.execute(SQL);
    } catch (SQLException e) {
      System.out.println("Erro no SQL:" + e.getMessage());
      return false;
    }

    return true;
  }