예제 #1
0
  public Cube selecionarId(String id) {
    String query = "SELECT * FROM cubo WHERE id = ?";

    Cube cubo = new Cube();
    try (PreparedStatement st = conn.prepareStatement(query)) {
      st.setString(1, id);
      ResultSet rs = st.executeQuery();

      if (rs.next()) {
        cubo.setId(rs.getInt(1));
        cubo.setNome(rs.getString(2));
        cubo.setTamanho(rs.getString(3));
        cubo.setTipo(rs.getString(4));
        cubo.setDificuldade(rs.getString(5));
        cubo.setImagem(rs.getString(6));
        cubo.setPreco(rs.getDouble(7));
      }
    } catch (SQLException sqe) {
      sqe.printStackTrace();
    }
    return cubo;
  }
예제 #2
0
  public List<Cube> carregarAll() {
    String sql = "SELECT * FROM cubo ORDER BY id";
    List<Cube> lista = new ArrayList<Cube>();
    try (PreparedStatement st = conn.prepareStatement(sql);
        ResultSet rs = st.executeQuery()) {

      while (rs.next()) {
        Cube cubo = new Cube();
        cubo.setId(rs.getInt(1));
        cubo.setNome(rs.getString(2));
        cubo.setTamanho(rs.getString(3));
        cubo.setTipo(rs.getString(4));
        cubo.setDificuldade(rs.getString(5));
        cubo.setImagem(rs.getString(6));
        cubo.setPreco(rs.getDouble(7));
        lista.add(cubo);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return lista;
  }