MySQL中的IN运算符以及Java中的预处理语句

时间:2019-05-13 12:52:07

标签: java mysql

这是我的逗号分隔值字符串的样子:

String commasepratedvalues = 2027237317405617, 2690460807646555,

commasepratedvalues中可以有任意多个值

MySQL查询:

"SELECT page_id, ps_id from fb_subscriptions WHERE ps_id IN (?)"

这是我传递值的方式:

    preparedStatement.setString(1, commaSepratedString);

这将导致

 SELECT page_id, ps_id from fb_subscriptions WHERE ps_id IN ('2027237317405617, 2690460807646555')

而不是

SELECT page_id, ps_id from fb_subscriptions WHERE ps_id IN (2027237317405617, 2690460807646555)

OR

SELECT page_id, ps_id from fb_subscriptions WHERE ps_id IN ('2027237317405617', '2690460807646555')

我知道这种情况的发生是因为我通过了一个?(准备好的语句标记)并使用了setString,这引起了我的价值观周围的双引号,但是我如何以最快的方式获得期望的格式呢?

0 个答案:

没有答案