spring-jdbc
The docs for spring-jdbc
are basically here:
https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html
Though it doesn't specifically point you to the Spring project spring-jdbc
. This project just provides all of the Spring abstractions over the plain JDBC DataSource
that you can use with the Spring Framework. For example, Spring's DataSource
s which nicely hook into Spring's Transaction management capabilities, like the @Transactional
annotation.
Also, the JdbcTemplate
is part of this module, which allows you to execute SQL statements and extract objects from ResultSet
s without dealing with exception handling or the nasty details of properly closing statements, connections and the like.
spring-data-jdbc
spring-data-jdbc
, on the other hand, provides the Spring Data abstraction over spring-jdbc
. That is, you can create a Spring Data CrudRepository
and a simple "entity" (not a JPA entity!) and, as Spring Data does, it will create your queries for you without you having to write native CRUD queries over JDBC, as in this example on the spring-data-examples
git repo.
Using the referenced example as a demonstration:
interface CategoryRepository extends CrudRepository<Category, Long> {}
The above code is all you could need (using introspection on the Category
object name as the source for the table name (based on a NamingStrategy
) and it's properties as columns, again similar to JPA, but not using JPA.
Rather than writing your own like so:
@Repository
public class CategoryRepository {
public void create(Category category) {
jdbcTemplate.execute("insert...");
}
// The rest of my other CRUD operations
}