jdbctemplate count queryForInt and pass multiple parameters

二次信任 提交于 2020-06-11 20:12:43

问题


How can I pass multiple parameters in jdbcTemplate queryForInt to get the count. I have tried this,

Integer count = this.jdbcTemplate
    .queryForInt("select count(name) from table_name where parameter1 = ? and parameter2 = ?", new Object[]{parameter1,parameter2});

But its showing queryForInt as strikes.


回答1:


Both queryForInt() and queryForLong() are deprecated since version 3.2.2 (correct me if mistake). To fix it, replace the code with queryForObject(String, Class).

 this.jdbcTemplate.queryForObject(
                    sql, new Object[] { parameter1,parameter2 }, Integer.class);

As per spring docs

int queryForInt(String sql, Map args)

Deprecated. Query for an int passing in a SQL query using the named parameter support provided by the NamedParameterJdbcTemplate and a map containing the arguments.

int queryForInt(String sql, Object... args) Deprecated.

Query for an int passing in a SQL query using the standard '?' placeholders for parameters and a variable number of arguments. int queryForInt(String sql, SqlParameterSource args) Deprecated. Query for an int passing in a SQL query using the named parameter support provided by the NamedParameterJdbcTemplate and a SqlParameterSource containing the arguments.



来源:https://stackoverflow.com/questions/34216124/jdbctemplate-count-queryforint-and-pass-multiple-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!