java jdbctemplate 计数 queryForInt 并传递多个参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34216124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jdbctemplate count queryForInt and pass multiple parameters
提问by Shijin Bhaskar
How can I pass multiple parameters in jdbcTemplate
queryForInt
to get the count. I have tried this,
如何传入多个参数jdbcTemplate
queryForInt
以获取计数。我试过这个,
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.
但它显示queryForInt
为罢工。
回答by Naruto
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).
自 3.2.2 版起不推荐使用 queryForInt() 和 queryForLong()(如有错误,请纠正我)。要修复它,请将代码替换为 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.
int queryForInt(String sql, Map args)
已弃用。使用 NamedParameterJdbcTemplate 提供的命名参数支持和包含参数的映射查询传入 SQL 查询的 int。
int queryForInt(String sql, Object... args) 不推荐使用。
使用标准“?”查询传入 SQL 查询的 int 参数的占位符和可变数量的参数。int queryForInt(String sql, SqlParameterSource args) 已弃用。使用 NamedParameterJdbcTemplate 和包含参数的 SqlParameterSource 提供的命名参数支持,查询传入 SQL 查询的 int。