Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jdbctemplate count queryForInt并传递多个参数_Java_Spring Jdbc_Jdbctemplate - Fatal编程技术网

Java jdbctemplate count queryForInt并传递多个参数

Java jdbctemplate count queryForInt并传递多个参数,java,spring-jdbc,jdbctemplate,Java,Spring Jdbc,Jdbctemplate,如何在jdbcTemplatequeryForInt中传递多个参数以获取计数。我试过这个 Integer count = this.jdbcTemplate .queryForInt("select count(name) from table_name where parameter1 = ? and parameter2 = ?", new Object[]{parameter1,parameter2}); 但它显示出的queryForInt令人震惊 自3.2.2版以来,query

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

Integer count = this.jdbcTemplate
    .queryForInt("select count(name) from table_name where parameter1 = ? and parameter2 = ?", new Object[]{parameter1,parameter2});
但它显示出的
queryForInt
令人震惊

自3.2.2版以来,queryForInt()和queryForLong()都不推荐使用(如果有错误,请纠正我)。要修复此问题,请将代码替换为queryForObject(字符串,类)

依照

int queryForInt(字符串sql、映射参数)

已弃用。 使用NamedParameterJdbcTemplate提供的命名参数支持和包含参数的映射,查询传入SQL查询的int

int queryForInt(字符串sql、对象…参数) 已弃用

使用参数的标准“?”占位符和可变数量的参数查询传入SQL查询的int。 int queryForInt(字符串sql、SqlParameterSource参数) 不赞成。 使用NamedParameterJdbcTemplate提供的命名参数支持和包含参数的SqlParameterSource查询传入SQL查询的int


如果答案有助于您解决问题,请将其标记为已接受。通过这种方式,它将帮助其他人寻找类似的问题。
 this.jdbcTemplate.queryForObject(
                    sql, new Object[] { parameter1,parameter2 }, Integer.class);