0
//Mysql Query to get project

while(query.next())
{
    Map objname=new Hashmap();
    //Mysql query to get day and hours of respective project
    while(dayandhourquery.next())
    {
        objname.put(day,hour);
    }
}

I've a query to get project name,days and hours.and I want to put day and hours in Hashmap with respective project. While doing this above code,I am getting the details with the last project.

3
  • 1
    I don't really understand what the actual problem is here, do you mind clarifying? Commented Nov 6, 2013 at 9:44
  • My first query gives me the project.With this project name I am fetching the day and hours. For each project I am adding day and hours in map. But right now with my logic I am getting the day and hours but only for last project name not for every project. Commented Nov 6, 2013 at 9:49
  • Hi @spydon is there any way to change MAP object dynamically... Commented Nov 6, 2013 at 9:51

1 Answer 1

1

It happen because Map stores only values for unique keys. I assume that for project days could be the same. When you put day value you override old day-hour entry in map. You need to consider changing key value in map or use one collection for each project.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi Areo can you please share me any example if you have ??
In your while loop you need to get project identifier. Based on it you need to add day-hour entry to correct collection. First solution could be having Map<String, List<DayTimeEntry> where key is your project id and DayTimeEntry is a class that holds day and hour information.
For every project there is different day and hour information.We need day as key and hour as value for each project.Can you give with an example?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.