Is there Java library like Spring JDBC Template, with same quality of code and documentation and similar data access exceptions hierarchy, but without dependancies on other Spring modules (core/beans/context modules according to http://mvnrepository.com/artifact/org.springframework/spring-jdbc/3.0.6.RELEASE)?
Spring-jdbc has direct dependency to the following libraries: spring-core , spring-beans and spring-tx . The rest of the dependencies are optional, so you don't need them actually.
The JdbcTemplate class executes SQL queries, iterates over the ResultSet , and retrieves the called values, updates the instructions and procedure calls, “catches” the exceptions, and translates them into the exceptions defined in the org. springframwork.
Because we use spring-jdbc , Spring Boot automatically creates a JdbcTemplate . The @Autowired JdbcTemplate field automatically loads it and makes it available. This Application class implements Spring Boot's CommandLineRunner , which means it will execute the run() method after the application context is loaded.
The Spring JDBC Template has the following advantages compared with standard JDBC. The Spring JDBC template allows to clean-up the resources automatically, e.g. release the database connections. The Spring JDBC template converts the standard JDBC SQLExceptions into RuntimeExceptions.
A minor correction to the accepted answer. As far as I can tell there is at least one more jar required. It comes into play exactly when data access exception hierarchy is accessed (an exception is thrown by underlying database driver and it's wrapped into Spring exception). The jar is spring-asm (byte-code manipulation). I discovered it accidentally when I had a problem in my SQL query and stack trace showed something like MissingClassException. (I would to prefer just to add a comment to the answer, but it looks I'm not eligible yet).
Spring-jdbc has direct dependency to the following libraries: spring-core
, spring-beans
and spring-tx
. The rest of the dependencies are optional, so you don't need them actually.
If these dependencies are already a lot for you, then you might have a look at Apache DbUtils.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With