Bober02
Bober02

Reputation: 15331

Spring - get ResultsSet from query

I would like to use Spring JDBCTemplate but I would like to receive a ResultSet, which is not storing full query result in memory, as you would find executing standard statement with java JDBC. The closest I found to the ResultSet was

SqlRowSet sqlRowSet = template.getJdbcOperations().queryForRowSet(query, queryParameters);

but this loads the whole DB result into memory?

Upvotes: 6

Views: 3724

Answers (2)

ChuyAMS
ChuyAMS

Reputation: 500

If you want to get a ResultSet object with JDBCTemplate you can retrieve the javax.sql.Connection with the following code:

Connection conn = jdbcTemplate.getDataSource().getConnection();

And you can now perform a createStatement() or preparedStatement() to get the ResultSet object. That's the only way it comes to my mind. I hope this will help you.

Upvotes: 4

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 135992

Is it what you are looking for?

    JdbcTemplate t = new JdbcTemplate(dataSource);
    t.query("select * from t1", new ResultSetExtractor<Object>() {
        public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
            ... process your rs
            return null;
        }
    });

Upvotes: 3

Related Questions