gpt4 book ai didi

java - jdbctemplate count queryForInt 并传递多个参数

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:50:21 25 4
gpt4 key购买 nike

如何在 jdbcTemplate queryForInt 中传递多个参数来获取计数。这个我试过了,

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

但它显示 queryForInt 作为罢工。

最佳答案

queryForInt() 和 queryForLong() 自版本 3.2.2 起已弃用(如有错误请指正)。要修复它,请将代码替换为 queryForObject(String, Class)。

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

根据 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.

关于java - jdbctemplate count queryForInt 并传递多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34216124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com