Beispiel #1
0
  public static List<User> loadAllUsers(DbUnitManager dbUnitManager) throws SQLException {
    Connection conn = dbUnitManager.getConnection();
    PreparedStatement ps = conn.prepareStatement("SELECT id, email, name FROM User");
    List<User> userList = new ArrayList<User>();

    try {
      ResultSet rs = ps.executeQuery();

      while (rs.next()) {
        userList.add(new User(rs.getLong("id"), rs.getString("email"), rs.getString("name")));
      }
    } finally {
      conn.close();
      ps.close();
    }

    return userList;
  }
Beispiel #2
0
  public static List<Contact> loadAllContacts(DbUnitManager dbUnitManager) throws SQLException {
    Connection conn = dbUnitManager.getConnection();
    PreparedStatement ps = conn.prepareStatement("SELECT id, phone, user_id FROM Contact");
    List<Contact> contactList = new ArrayList<Contact>();

    try {
      ResultSet rs = ps.executeQuery();

      while (rs.next()) {
        Long userId = rs.getLong("user_id");

        if (userId == null || userId.intValue() == 0) {
          contactList.add(new Contact(rs.getLong("id"), rs.getString("phone")));
        } else {
          contactList.add(new Contact(rs.getLong("id"), rs.getString("phone"), userId));
        }
      }
    } finally {
      conn.close();
      ps.close();
    }

    return contactList;
  }