如何在春季使用jdbcTemplate传递多个值以进行查询 [英] how to pass multiple values to query using jdbcTemplate in spring

查看:116
本文介绍了如何在春季使用jdbcTemplate传递多个值以进行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Spring Hibernate应用程序中,我将所有sql查询都放在一个common_queries.xml文件中,其中一些查询需要2至3个参数,如下所示

In my Spring Hibernate application i have all the sql queries in one common_queries.xml file,where some queries require 2 to 3 parameters shown as below

   <query id="mining.fuel" no-of-params="2">
select ms.id id,ms.name value,concat(ms.name,' ','  (',ms.code,')') label,ms.rate rate     from mining_fuel ms where ms.name like '?' and ms.fuel_type_id=?  LIMIT 10
 </query>   

在我的daoImpl中,我得到了这个查询

In my daoImpl i get this query

lookupList = jdbcTemplate.queryForList(q1.getQuery());

我将在这里获取查询,但是如何在此处传递'?'的值,我在daoImpl中有这两个值.声明.

I will get the query here,but how to pass the value of '?'s here, i have those 2 values with me in daoImpl.. pl send the code of how to achieve this.I dont want to use prepared statement.

推荐答案

使用

Use this overload which takes an Object vararg for passing the query parameters:

lookupList = jdbcTemplate.queryForList(q1.getQuery(), value1, value2, value3);

这篇关于如何在春季使用jdbcTemplate传递多个值以进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆