Spring JdbcTemplate Example

Remember below version only supports com.mysql.jdbc.Driver

We need to create pojo according to table. Properties of pojo will be column names. Not compulsorily same name but as a standard we will keep same name.

Remember as a standard implement getters and setters, constructor and override toString, equals, hashcode method.

hashCode and equals methods need for comparing objects in a test cases.


This class needs to be created for mapping employee pojo and column of table. Generally we can say if I have 10 tables then like this we need to have 10 classes for mapping.

  1. In this class we must autowire JdbcTemplate.

  2. This class must be qualified bean so annotate class with repository annotation.

In above program we can see:

  1. DML operations can be performed by using update method.

  2. Select operation are achieved by query and queryForObject method.

  3. Observe in these all scenarios we have control over queries that’s beauty of JdbcTemplate.

  4. In hibernate most of the time we not get control.

  5. In pure jdbc lot of code needs to be written for connection.

Now our setup is ready.

We will start testing application.