Topic: 问个 java.sql.PreparedStatement 的问题

  Print this page

1.问个 java.sql.PreparedStatement 的问题 Copy to clipboard
Posted by: sandish
Posted on: 2006-04-18 15:04

比如:
select * from CMNG_CUSTOM where AREAID in ( ? )
这个参数的值想动态传进去,比如 String areas = "'0101','0202','0303'";
不行。

我测试了一下,发现,如果
pstmt.setString(1,"0101")进去后,是可以的,
而pstmt.setString(1,"'0101'")却不行,可能是PreparedStatement 在setString的时候,自动前后加了两个单引号。按照这种想法,我先去掉前后的单引号,变成 0101','0202','0303
pstmt.setString(1,"0101','0202','0303") 也不行。

不知道通过什么方法可以?

2.Re:问个 java.sql.PreparedStatement 的问题 [Re: sandish] Copy to clipboard
Posted by: wt_adam
Posted on: 2006-07-10 11:00

试一下pstmt.setString(1,"0101,0202,0303");

3.Re:问个 java.sql.PreparedStatement 的问题 [Re: sandish] Copy to clipboard
Posted by: why
Posted on: 2006-07-10 18:43

I'm afraid JDBC's PreparedStatement doesn't have this feature.

If you have a maximum limit of number of parameters in the IN clause, you could (but not really recommended to) use (say, max is 4)
IN (?,?,?,?)
and supply duplicated values if there are less than 4 values.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923