title: Using RowMapper to return Map<String,Map<String,List<Object>>>
body: <p>Each row in my DB is going to be like this </p>
  
  <pre><code>School  Class   StudentID   Name    Age
  123      8        811       John    10
  123      8        812       Smith   11
  123      8        821       John    12
  123      8        822       Smith   13
  123      9        911       John    14
  123      9        912       Smith   15
  456      8        811       John    10
  456      8        812       Smith   11
  </code></pre>
  
  <p>Now I want to return the above data like this</p>
  
  <pre><code>Map&lt;String,Map&lt;String,List&lt;Object&gt;&gt;&gt;
  
  ie. Map&lt;School,Map&lt;Class,List&lt;StudentID&gt;&gt;&gt;
  </code></pre>
  
  <p>I am using Spring's <code>JdbcTemplate</code> with a <code>RowMapper</code> but all I can get is an List of all the rows. Since I wont be able to maintain my main Map in my RowMapper (<em>can I have a static map inside the RowMapper class ?? but I do not want it to be static as this is a webservice and subsequent calls might get screwed.</em>), I only have the option to get this Row list and then have my logic to create the Collection that I want.</p>
  
  <p>I came to know about <code>ResultSetExtractor</code> but I could not find how to get this done using that.</p>
  
  <p>Please let me know if there is any way I can get this done using a row mapper or some sort. Or my only way to solve this is my having to iterate the list again and get what I want.</p>
  
  <p><strong>EDIT:</strong> 
  My query is a select query like this:</p>
  
  <pre><code>SELECT * from TABLENAME
  </code></pre>
  
  <p>and it actually takes 40 minutes to retrieve the ResultSet from Java.</p>
  
  <p>Since the DB call is for filling the cache object which is done using CRON every 4 hours, I don't mind the time delay of 40 minutes since the actual REST calls, will be referring to the cache object. But still I want to do this as efficiently as possible.</p>
  
  <p>Also please let me know if there is any other way I can handle this scenario. A normal jdbc call for every REST call wll be costly,since we will be getting 100's of requests per second.</p>