在prepareStatement中使用可变数量的参数 [英] working with variable number of parameters in a preparedStatement

查看:276
本文介绍了在prepareStatement中使用可变数量的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序创建搜索表单.
用户在其中选择应用于过滤数据的字段.
数字字段是可变的,所以我不知道SQL查询的where子句中应该有多少?.
如何在where子句中使用具有可变数量条件的preparedStatement?

I'm creating a search form for my application.
In it user selects fields that should be used in filtering data.
the number fields is variable so I don't know how many ? should be in where clause of SQL query.
How can I use preparedStatement with variable number of conditions in where clause?

谢谢

推荐答案

PrepardStatements不支持可变数量的条件.一些框架的作用是将每个PreparedStatement缓存在Map中,键是查询.

PrepardStatements don't support variable numbers of conditions. What some frameworks do, is they cache each PreparedStatement in a Map where the key is the query.

因此,每次您要运行查询时,都需要构建字符串以创建PreparedStatement,检查它是否在地图中(并重用)或创建一个新字符串,然后将其添加到地图中.

So each time you want to run a query, you need to build the string to create the PreparedStatement, check if you have it in the map (and reuse it) or create a new one, and add it to the map.

这篇关于在prepareStatement中使用可变数量的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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