K. Tsang wrote:Based on your current approach, Ankit is right - your Game class can be public. In fact Team and Game are 2 different things so why not Game public.
Now if Game is public there shouldn't be any problem because you are not trying to access some inner class thing.
I also noticed your Game class is immutable (eg not set methods). Nice.
Jhakda Velu wrote:Hi
I won't give you the complete solution,but would give you a few pointers.
Use order by clause in your sql(say on home team) to get teams in a particular order.
While iterating through your resultset create a new instance of your Team VO if the previous team_name and the current is not the same(this is the reason for order by) .You will also need 2 variables to count number of wins and losses. This should be reset to 0 every time a new team is encountered.
You can have a Arraylist for opponents,keeping in mind that data will repeat every 4 elements(opponent_name,location, for,against).
Each Team VO should then be added to a collection which should be used to form the XML.
Jhakda Velu wrote:Hi
Can you give the exact table structure,that way i can hint about the possible query to use.
The HashMap example in my previous post should show you the direction. Try making a hashmap and add key value pairs to it and test.
Jhakda Velu wrote:Hi
I would try to fetch only the required data by tweaking the SQL. This way, i need to hit the DB only once and i need not check for duplicates.
In case you wish to use the HashMap approach, the key will be a string(the team name fetched from DB) and value can be the Team object created while iterating through the second resultset,duplicate values will be rejected, but here, there is an overhead of extra iterations.
Jhakda Velu wrote:
Think of other ways to do this and people here would help you come out with good solutions(managing through SQL itself, using a HashMap with "home_team" as key and Team object as value(assuming you need a Team object(containing other attributes that you may fetch from the Database) and not just team names),etc etc).
Jhakda
Campbell Ritchie wrote:Art Vandelay, welcome to JavaRanch
The answer for this question is "String Version" Please tell me why?