JdbcTemplate queryForInt/Long is deprecated in Spring 3.2.2. What should it be replaced by?

后端 未结 6 1446
慢半拍i
慢半拍i 2021-01-30 19:36

The queryforInt/queryforLong methods in JdbcTemplate are deprecated in Spring 3.2. I can\'t find out why or what is considered the best practice to replace existing code using t

6条回答
  •  离开以前
    2021-01-30 19:41

    I agree with the original poster that deprecating the convenience method queryForLong(sql) is an inconvenience.

    I had developed an app using Spring 3.1 and just updated to the latest Spring version (3.2.3) and noticed that it was deprecated.

    Fortunately, it was a one line change for me:

    return jdbcTemplate.queryForLong(sql);  // deprecated in Spring 3.2.x
    

    was changed to

    return jdbcTemplate.queryForObject(sql, Long.class);
    

    And a couple of Unit Tests seem to indicate, the above change works.

提交回复
热议问题