Announcement Announcement Module
Collapse
No announcement yet.
How to make JDBCTemplate use connected resultsets Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to make JDBCTemplate use connected resultsets

    We would like to use JDBCTemplate for data access purposes due to the programming conveniences it offers.

    I saw in the API that the query methods return a SqlRowSet, the implementation for SqlRowSet, ResultSetMappingSqlRowSet seems to use a disconnected resultset by default and the documentation seems to mention that a connected resultset could be provided.

    I wanted to know how to make the SqlRowSet implementation classes use a connected resultset. I was not able to find any documentation to enable me to do that.

    Any help is highly appreciated.

  • #2
    What is it exactly that you want to do? Do you really want to work with the SqlRowSet? RowMapper is quite a useful feature if you just want to transform objects from the database, the reference manual has lots of examples.
    http://www.springframework.org/docs/...plate-examples

    Comment


    • #3
      RowMapper just assists in mapping the resultset data for a row into an object.

      What we want to accomplish is not to bring back all the data from a query into memory as we will be querying a large amount of data (500,000+ records). I did not find anyway to use a connected resultset to accomplish this.

      Comment


      • #4
        Look for a JdbcTemplate query method that takes a RowCallbackHandler or a ResultSetExtractor. That should give you a way of handling the result set without having to create an object for each row.

        Using a connected RowSet would be much more work on your part and you would then depend on the RowSet implementation not holding on to the memory. That could also be an issue depending on what JDBC driver you use. Some of them don't release the memory as you iterate over the rows.

        Comment


        • #5
          I have a need to get a reference to a connected resultset while using Spring's JDBC classes. I know that the RowCallbackHandler / ResultSetExtractor use a connected resultset, but I want to get a direct reference to a resultset object, as I want to avoid dealing with callbacks. Does anyone know how to get hold of a connected resultset object?

          Comment


          • #6
            Spring doesn't keep the connection active, so you can't have a connected resultset. You would have to code that using regular straight JDBC code. You can still participate in Spring managed transactions using either DataSourceUtils.getConnection(DataSource dataSource) or by using a TransactionAwareDataSourceProxy.

            Comment


            • #7
              thanks for you DataSourceUtils suggestion, since I am coding regular straight JDBC can I use NamedParameterUtils spring class for named parameter sql parsing. This will help us a lot, this class is only intended for internal use within Spring's JDBC framework. I want stick to using spring jdbc as much as possible.

              Comment


              • #8
                The NamedParameterUtils should be OK to use - just look at the source to determine that the method you are using is doing what you want.

                Comment

                Working...
                X