Results 1 to 3 of 3

Thread: Extract java.sql.ResultSet using JdbcTemplate

  1. #1
    Join Date
    Apr 2005
    Posts
    2

    Default Extract java.sql.ResultSet using JdbcTemplate

    Hi,

    Are there any methods to obtain ResultSet that implemented by JDBC-driver from JdbcTemplate ?

    I have tried methods:
    Code:
    execute(PrepareStatementCreator,  PreparedStatementCallback action)
    query(PrepareStatementCreator, ResultSetExtractor)
    but with all my implementations of these interfaces , I recieved SQL exception - Object has been closed.

    I have tried to use SqlRowSetResultSetExtractor but its not exactly what I need - SqlRowSet doesn't implement all methods of RowSet (for example, method getBinaryStream() is absent), resultset metadata different with metadata from JDBC-driver implementation of ResultSet etc

    There can be ideologically I do something incorrectly?

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    What exactly are you trying to do?
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Apr 2005
    Posts
    2

    Default

    Thank you for attention,

    My task step by step looks like
    • 1) execute prepared SQL query
      2) extract ResultSet that implemented by specific JDBC driver (its important – I need implementation from driver jar)
      3) extract from ResultSet columns java types and columns values

    I have to solve two problems
    • 1) huge number of records - work directly with ResultSet instead of temporary collections
      2) convert SQL types of columns to java types - different databases give me different results, so I don't want to use any converters, I'm extracting this information from ResultSet

    My working code
    Code:
        public static SqlRowSet executeQuery(JDBCConnection jdbcConnection, String sql, List parameters, Map values) {
    
        configureDatasource(jdbcConnection);
        JdbcTemplate template = new JdbcTemplate(datasource);
    
        SqlRowSet resultSet = (SqlRowSet ) 
                 template.query(new ParametersSetter(sql, parameters, values),  
                                        new SqlRowSetResultSetExtractor());
    
            return resultSet;
        }
    The received result set has following lacks
    • 1) interface SqlRowSet doesn't implement method java.sql.ResultSet.getBinaryStream()
      2) this result set is an instance of com.sun.rowset.CachedRowSetImpl , matadata of this result set is an instance of javax.sql.rowset.RowSetMetaDataImpl. When I try to extract java type of column from metadata with getColumnClassNamecolumn), I recieved type that differ with type that can be extracted from generic result set
      (for example, MS SQL driver interprets SQL-type SMALLINT as Integer while RowSetMetaDataImpl gives me Short )

    I'm newby with Spring, so may be you explain me my possible errors

    Thanks in advance,
    Andrey

Similar Threads

  1. Replies: 3
    Last Post: Mar 1st, 2010, 05:45 PM
  2. CMT, JdbcTemplate and connection pools
    By jayschm in forum EJB
    Replies: 3
    Last Post: Apr 25th, 2005, 08:11 AM
  3. Replies: 8
    Last Post: Jan 9th, 2005, 10:24 AM
  4. Injecting JdbcTemplate instead of just DataSource?
    By ArtVandelay in forum Container
    Replies: 4
    Last Post: Oct 20th, 2004, 10:22 PM
  5. Replies: 1
    Last Post: Oct 16th, 2004, 07:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •