Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring JDBC template without Spring

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)?

like image 988
Peter Štibraný Avatar asked Dec 07 '11 12:12

Peter Štibraný


People also ask

Can we use JdbcTemplate without spring?

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.

How does Spring JDBC template work?

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.

Can we use JdbcTemplate in spring boot?

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.

What is Spring JDBC How is different from JDBC?

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.


2 Answers

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).

like image 133
mp31415 Avatar answered Oct 18 '22 04:10

mp31415


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.

like image 14
melihcelik Avatar answered Oct 18 '22 04:10

melihcelik