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.




Software Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Hard way to master a programming language

Picture with the code written on a laptop

Exploring an alternative to Spring Boot

A tale of two SaaS support models

Indifferent Access with Elixir/Phoenix App

what i have been waiting for has come !

Does Iterative Adversarial Training Repel White-box Adversarial Attack

What happens when you type gcc main.c?

My Top 5 VSCode Extensions

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Furkan Topal

Furkan Topal

Software Engineer

More from Medium

Java Collections

Java Date,Time With Data type and Epoch

Introduction to Java