title: Resultset Metadata from Spring JDBCTemplate Query methods
body: <p>Is there any way I can get resultset object from one of jdbctemplate query methods?</p>
  
  <p>I have a code like</p>
  
  <pre><code>List&lt;ResultSet&gt; rsList = template.query(finalQuery, new RowMapper&lt;ResultSet&gt;() {
          public ResultSet mapRow(ResultSet rs, int rowNum) throws SQLException {
              return rs;
          }
          }
          );
  </code></pre>
  
  <p>I wanted to execute my sql statement stored in finalQuery String and get the resultset. The query is a complex join on 6 to 7 tables and I am select 4-5 columns from each table and wanted to get the metadata of those columns to transform data types and data to downstream systems.</p>
  
  <p>If it is a simple query and I am fetching form only one table I can use RowMapper#mapRow and inside that maprow method i can call ResultsetExtractor.extractData to get list of results; but in this case I have complex joins in my query and I am trying to get resultset Object and from that resultset metadata... </p>
  
  <p>The above code is not good because for each result it will return same resultset object and I dont want to store them in list ...</p>
  
  <p>Once more thing is if maprow is called for each result from my query will JDBCTemplate close the rs and connection even though my list has reference to RS object?</p>
  
  <p>Is there any simple method like jdbcTemplate.queryForResultSet(sql) ? </p>
  
  <p>Now I have implemented my own ResultSet Extractor to process and insert data into downstream systems</p>
  
  <pre><code>sourceJdbcTemplate.query(finalQuery, new CustomResultSetProcessor(targetTable, targetJdbcTemplate));
  </code></pre>
  
  <p>This CustomResultSetProcessor implements ResultSetExtractor and in extractData method I am calling 3 different methods 1 is get ColumnTypes form rs.getMetaData() and second is getColumnTypes of target metadata by running</p>
  
  <pre><code>SELECT NAME, COLTYPE, TBNAME FROM SYSIBM.SYSCOLUMNS WHERE TBNAME ='TABLENAME' AND TABCREATOR='TABLE CREATOR'
  </code></pre>
  
  <p>and in 3rd method I am building the insert statement (prepared) form target columntypes and finally calling that using</p>
  
  <pre><code>new BatchPreparedStatementSetter()
      {
          @Override
          public void setValues(PreparedStatement insertStmt, int i) throws SQLException{} }
  </code></pre>
  
  <p>Hope this helps to others...</p>