Link to home
Start Free TrialLog in
Avatar of Nika Gudge
Nika GudgeFlag for United States of America

asked on

how to add object to map?

I'm trying to add the records fetched from select query to a map.
Below is list implementation. it adds the employee object to the list :
      
      public List<Employee> getEmployee() throws Exception {
            String sql = "select * from Employee";
            List< Employee > emp = new ArrayList< Employee>();
            try {
                  emp  = (List< Employee >) jdbcTemplate.query(sql, new Object[]{}, new EmployeeMapper());
            } catch (Exception e)
            {
                throw new Exception("Exception occured while getting the emp ID :",e);
            }
            return emp;
      }

I need the map implementation which will store the primary key as the key and the remaining columns(object) as the value in the map.
for ex:
employee:
[Key]->empId  [Value]->[empNm    empCode     empAddr        empSal]
1                                         John          123                123 main st     4000
2                                        Doe            456                546 main st     6000
Map<String[empid], Object[employee]>
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nika Gudge

ASKER

worked