Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8684427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:18:16+00:00 2026-06-12T22:18:16+00:00

I have some values return from database as a result set like following **resource_name

  • 0

I have some values return from database as a result set like following

**resource_name         menu_name       menu_group_name**
DepartmentAction        Department      Admin Operation
PositionAction          Position        Admin Operation
FoodHabitAction         FoodHabits      Admin Operation
ReligiousAction         Religious       Admin Operation
NationalitiesAction     Nationlities    Admin Operation

I would like to group resource_name and menu_mane based on menu_group_name
some thing like the following

 if the menu_group_name is same than group all the corresponding
    resource_name and menu_mane against to menu_group_name .

UPDATE :

 public Map<String,List> getMenuForLoggedinRole(int roleid){
        Map<String,List> menuListMap = new LinkedHashMap<String,List>();
        List<MenuListViewModel> menuNamesList = new ArrayList<MenuListViewModel>();
        MenuListViewModel menuViewModel;
        Connection connection = getConnection();
        PreparedStatement ps = null;
        ResultSet rs = null;
        if (connection != null) {
            try {
                ps = connection.prepareStatement(" select ar.resource_name,ar.menu_name,mg.menu_group_name "
                        + " from m_application_resources as ar,"
                        + " m_menu_groups as mg,m_access_matrix as amatrix "
                        + " where ar.resourceid = amatrix.resourceid and amatrix.roleid=?");
                ps.setInt(1, roleid);
                rs = ps.executeQuery();
                if(rs.next()) {
                   String menu_group_name = rs.getString("menu_group_name");
                   String resource_name = rs.getString("resource_name");
                   String menu_name = rs.getString("menu_name");
                   if(menuListMap.containsKey(menu_group_name)){
                       menuNamesList =(List) menuListMap.get(menu_group_name);
                       menuViewModel = new MenuListViewModel();
                       menuViewModel.setResource_name(resource_name);
                       menuViewModel.setMenu_name(menu_name);
                       menuNamesList.add(menuViewModel);
                       menuListMap.put(menu_group_name, menuNamesList);
                   }else{
                       menuViewModel = new MenuListViewModel();
                       menuViewModel.setResource_name(resource_name);
                       menuViewModel.setMenu_name(menu_name);
                       menuNamesList.add(menuViewModel);
                       menuListMap.put(menu_group_name, menuNamesList);
                   }
                } 
            } catch (Exception ex) {
                ex.printStackTrace();
            }finally {
                try {
                    closeConnection(connection, rs, ps);
                } catch (Exception ex) {
                    ex.printStackTrace();
                    //use logger here
                }
            }
        }

        printMap(menuListMap);
        return menuListMap;
    }

when i printed and saw only one value is getting printed others are not.
Please help me how to do this.
i know that it is very simple needs your help.

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:18:17+00:00Added an answer on June 12, 2026 at 10:18 pm

    create some class,CustomClass, with members resource_name and menu_name

    now create a map<String, List<CustomClass>>

    iterate over resultset and keep adding data to map

    menu_group_name will be your key and customclass you have created will be value, while putting data in map, check if that key exists, if yes retrive list and add new customclass to it else create a new list with your customclass and add put key value pair

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some values return from database as a result set like following **resource_name
I have a hashtable . values() method returns values in some order different from
I have some values in a configuration file (XML file) with some values like
I have a method that gets rows from my database. It looks like this:
I use the following stored procedure from my SQL Server 2008 database to return
I have some items in database. Each of'em can have many tags, like Browsable,
I have some values in a dataframe called 'values' ie: Sam Ned Ted Ann
In my C++ application, I have some values that act as codes to represent
I have some default values for testing my code, but for security reasons those
I have some financial values stored as text in a mysql db. the significance

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.