I was debating my self whether to use jdbcTemplate vs apache DBUtils in my project. My application is a spring app, where we are using jdbcTemplate for few requests. But i was thinking about this very lightweight and easy to understand Apache DbUtils.
I know both jdbcTemplate and dbutils are abstraction layer on top of regular JDBC which helps us to avoid broiler plate code.
So My questions are:
1) Any strong reason i should convince myself to migrate everything from jdbcTemplate to dbutils?
2)Any Auto POJO mappers in jdbcTemplate which automaps to java POJO class?In DbUtils i know we can do this like below:
ResultSetHandler<List<Object>> beanListHandler = new BeanListHandler<Object>(Object.class, new BasicRowProcessor(new GenerousBeanProcessor())); I
In jdbcTemplate i know we can have a custom rowMapper where we can explicitly set the properties like below, but is there a way to do auto mapping to POJOS like in dbutils?
@Overides
public Object mapRow(){
//set to Object by calling setters
}
3)Performance wise will it make any difference using dbutils?(As we are already using jdbcTemplate in other requests)
Can anyone suggest the best to chose from these two and why from your experience?
If your application is using Spring framework then you should stick to using JdbcTemplate. Working in tandem with Spring framework it offers many benefits, some of the key ones are
and not to forget, plenty of material is available on internet for this combination, should you get stuck at any point and try to look for pointers.
What you can do to reduce boiler plate around data extraction (from ResultSet) and creating POJOs though, is, write some generic implementations of RowMapper (or ResultSetExtractor). The implementation should probe the ResultsetMetadata to determine column names and types of returned records and with a bit of Reflection on Class (object of which RowMapper should return) match them to fields or setters, instantiate, fill and return the object.