Using Spring JDBC Templates

Spring are rolling out regular updates to their Data module, a recent release as part of the JDBC-Extensions update includes support for QueryDSL which means we should never need to write another line of static SQL in Java ever again.

This is not completely true, there is a time and a place for static SQL. For complex reports, there is often no other solution. The queries written for complex reports shouldn’t really be wired into the core code though, they should really be pushed down to the custom reporting application or just developed in separate packages keeping the core Services and DAO’s clean.

Why is static SQL not a good idea? It is difficult to maintain, often mixes business logic with data access, and it’s an open door for SQL Injection security issues.

Here are some useful links which will be an interesting read if you have some static SQL that is not hibernate based and you would like to cleanup any Spring JDBC templated code.

JDBC-Extension update page:

http://www.springsource.org/spring-data/jdbc-extensions

JDBC-Extensions reference page:

http://static.springsource.org/spring-data/data-jdbc/docs/1.0.0.RC1/reference…

Spring QueryDSL

http://static.springsource.org/spring-data/data-jdbc/docs/1.0.0.RC1/reference….querydsl

QueryDSL homepage

http://www.querydsl.com/