why we use MapSqlParameterSource

spring, spring-jdbc

Solution

It is because some developers do not like use `?` in a sql sentence. This `?` is named or referred how (mostly the first):

- Placeholders

- Bind parameter

Therefore Spring offers the same approach, it such as how Hibernate/JPA does with `:parameter`, it through the `MapSqlParameterSource` class.

I suggest you do a research about `RowMapper<T>` too.

Problem

I am new to spring world, in above code i understand query but i don't get why "new MapSqlParameterSource("username" ,username)" is used? ``` public boolean exists(String username) { return jdbc.queryForObject("select count(*) from users where username=:username", new MapSqlParameterSource("username" ,username),Integer.class)>0; } ``` what is the purpose of using it? Thanks in advance

Original source