I wrote codes like this. In the table (SocialLevelPerUser), there are two rows satifying the "WHERE-clause". However, the "while-statement" is run only one time. I don't understand why this happens. I am using PostgreSQL database. Any thoughts / comments appreciated. Thanks.
ArrayList<Friend> getFriendList(String userId){
ArrayList<Friend> friendList = new ArrayList<Friend>();
Friend eachFriend = new Friend();
try {
st = connection.createStatement();
rs = st.executeQuery("SELECT \"SourceName\", \"DestinationName\", \"Portion\" "
+ "FROM public.\"SocialLevelPerUser\" "
+ "WHERE \"SourceName\" = '" + userId + "'");
while(rs.next()){
eachFriend = new Friend();
String friendId = rs.getString("DestinationName");
double followingPortion = Double.parseDouble(rs.getString("Portion"));
eachFriend.setUserId(friendId);
eachFriend.setFollowingPortion(followingPortion);
boolean isComplete = isCompleteUserId(friendId);
boolean isFollow = isFollower(friendId, userId);
double followerPortion = getFollowerPortion(friendId, userId);
eachFriend.setIsCompleteUserId(isComplete);
eachFriend.setIsFollower(isFollow);
eachFriend.setFollowerPortion(followerPortion);
friendList.add(eachFriend);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return friendList;
}
I tried to input query on the client of PostgreSQL resulting in like below figure.