troubleshooting Question

how to add object to map?

Avatar of Newton21205
Newton21205 asked on
JavaOracle Database
2 Comments1 Solution106 ViewsLast Modified:
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
dpearson

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros