我想知道有没有办法查看到prepareStatement方式拼装SQL后,真正我拼装完执行的SQL?还有,如果我用prepareStatement方式拼装SQL,那么怎么合成带 IN 条件的SQL?比如: Select * from tb where tb.a in (?)这种能实现么?能的话,我应该怎么往里传参数?请高手指教~~
public static List findproperty(String canshu1, String canshu2)throws Exception{ StringBuffer hql = new StringBuffer("Select * from tb b where 1=1"); if (canshu1!= null && !"".equals(canshu1)) hql.append(" and b.列名 = " + canshu1); if (canshu2!= null && !"".equals(canshu2)) hql.append(" and b.列名 = " + canshu2); PreparedStatement ps = conn.prepareStatement(hql);
换成exists参考
http://oracle.chinaitlab.com/optimize/14505.html
而我要in 的部分,是别的业务传过来的,所以,不能这样,我只能循环执行了。
pst = conn.prepareStatement("SQL语句");
pst.setInt(1, id);//第一个问号
pst.setString(2, name);//第二个问号
....
hql.append(" and b.列名 = " + canshu1);
if (canshu2!= null && !"".equals(canshu2))
hql.append(" and b.列名 = " + canshu2);
PreparedStatement ps = conn.prepareStatement(hql);
Select * from tb where tb.a in (?)请问我这里的 ? 应该怎么传?pst.setString(1, "'01', '02'");这样么?
我debug下ps对象 就查到个originalSQL
也许有其它方式可以拼装
---------------------------------------
是这样的