How to Fetch Data From a Datasource with JDBCTemplate in Spring
You can either use JPA or JDBCTemplate for your Spring Boot project. Either of them has specific pros and cons for their use. JDBCTemplate let’s you low level access and gives you more freedom but you end up with comparatively more boilerplate. I will stick with JDBCTemplate for this time.
First of all I need a Model
Then I need a Dao but let me create an Interface first
Well, it needs an Implementation Class now
I called a new DemoRowMapper in the get method. Let’s create that.
You may wonder how I handle JdbcTemplate in the DataSourceConfig, there it is.
Showing properties file to make it clear won’t kill anybody. So I’m going to show that too.
From now on you can call get() method of your Implementation class by Autowiring it in your service.