문제

JDBC에 대한 Spring의 지원을 사용하고 있습니다. 사용하고 싶습니다 jdbctemplate (또는 simplejdbctemplate) 쿼리를 실행하고 결과 세트 인스턴스로 결과를 얻습니다.

이것을 달성 할 수있는 유일한 방법은 다음과 같습니다.

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

이 접근법의 명백한 단점은 SQLROWSET의 구현 유형에 대해 (캐스팅을 통해) 가정을해야한다는 것입니다. 그러나 더 나은 방법이 있습니까?

배경 정보 ...

콩 모음이 아닌 결과 세트로 결과를 얻고 싶은 이유는 결과가 디스플레이를 위해 재스퍼 보고서로 바로 전달되기 때문입니다. 다시 말해, Java Bean은 결과 세트에 각 행을 일시적으로 저장하는 것 외에는 아무것도 사용하지 않을 것이며 가능한 경우 모든 재스퍼 보고서에 대해 그러한 콩을 만드는 것을 피하고 싶습니다.

건배, 돈

도움이 되었습니까?

해결책

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.

다른 팁

You can either invoke Jasper inside a JdbcTemplate callback (like a ResultSetExtractor) or use straight JDBC to pass the ResultSet to Jasper. Either way when you call Jasper your connection to the database is still active until your report is finished.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top