views:

795

answers:

1

Hi,

I'm using Spring's support for JDBC. I'd like to use JdbcTemplate (or SimpleJdbcTemplate) to execute a query and obtain the result as an instance of ResultSet.

The only way that I can see of achieving this is using:

String sql = "select * from....";
SqlRowSet results = jdbcTemplate.queryForRowSet(sql);
((ResultSetWrappingSqlRowSet) results).getResultSet();

An obvious shortcoming of this approach is that it requires me to make an assumption (by casting) about the implementation type of SqlRowSet, but is there a better way?

Background info...

The reason I want to obtain the results as a ResultSet, rather than a collection of beans, is because the results will be passed straight to a Jasper report for display. In other words, the Java bean would be used for nothing other than temporarily storing each row in the ResultSet, and I'd like to avoid creating such a bean for every Jasper report if possible.

Cheers, Don

A: 

If you want to just perform a query and get the results, why don't you use plain jdbc and grab the resultset? Notice that you don't need spring to do just this.

    Connection c = ...
    c.prepareCall("select ...").getResultSet();

Besides, you get an advantage by using an object as a DTO. You don't need to change your DTO class even if your data acess or your report tool changes (let's say you start using xquery instead of jdbc or you use apache-poi instead of jasper.

Miguel Ping