Example #1
0
  public static Map<Long, Long> loadZutaten(Long id, Connection con) throws SQLException {
    Map<Long, Long> zutaten = new HashMap<Long, Long>();

    String sql = "select zut_id, menge from zut2rez where rez_id = ?";
    PreparedStatement stmt = null;
    StatementBuilder builder = new StatementBuilder();
    stmt = builder.buildQuery(sql, con);
    stmt.setLong(1, id);
    ResultSet rs = stmt.executeQuery();

    while (rs.next()) {
      zutaten.put(rs.getLong("zut_id"), rs.getLong("menge"));
    }

    return zutaten;
  }
Example #2
0
  public static List findRezepte(Query q, Connection con) throws SQLException {
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
      StatementBuilder builder = new StatementBuilder();
      builder.add("id", q.getExpression("id"));
      builder.add("name", q.getExpression("name"));
      builder.add("anleitung", q.getExpression("anleitung"));

      if (q.getResultType() == ResultType.NAMES) {
        stmt = builder.buildQuery("select id, name from rezept", con);

        return makeNameList(stmt.executeQuery());
      } else {
        stmt = builder.buildQuery("select id, name, anleitung, bzr_login from rezept ", con);
        return makeObjectList(stmt.executeQuery());
      }
    } finally {
      DbUtil.close(rs, stmt);
    }
  }