Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 问个 java.sql.PreparedStatement 的问题
sandish





发贴: 2
积分: 0
于 2006-04-18 15:04 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
比如:
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") 也不行。

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


why edited on 2006-07-10 18:26

作者 Re:问个 java.sql.PreparedStatement 的问题 [Re:sandish]
wt_adam





发贴: 6
积分: 0
于 2006-07-10 11:00 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
试一下pstmt.setString(1,"0101,0202,0303");


作者 Re:问个 java.sql.PreparedStatement 的问题 [Re:sandish]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-07-10 18:43 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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.


why edited on 2006-07-10 18:51


flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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