Java Persistence Architecture (JPA) is generally used in Java EE applications but can also be used directly in a Java SE program, see this article setting up JPA in a Java SE environment. However, you can get added advantages of running JPA in a web server environment and have your Java SE client programs access that, advantages such as:
- Better use of JPA connection pool and cache as these are shared amongst the clients
- Smaller client code without the need for full JPA and JPA implementation libraries
- Better security as clients don’t need to hold database login information
The problem is how to provide the access and still have pretty much the full functionality that JPA provides, this is where WebDAO comes in.
Spring Jdbc Template Example explains step by step details of configuring Spring Jdbc Template
The Spring Framework is a free and open source framework using for the development of java enterprise applications
Spring framework consists of several different modules including Aspect Oriented Programming, Inversion Control, Model View Controller, Data Access, Transaction Management, Batch Processing, Remote Access & Spring JDBC Template will really ease the development effort of coding team.
SpringJdbcTemplate is a module available in spring core framework, which will help you to persist entities by using very little code, it simplifies the creation of database connection & closing connection etc.
In this example, we are injecting the DataSource by setter injection, if you need you can configure using spring configuration.