String sql = "select distinct mobile,(select name from sms.t_union_info@sms22 where unionid=t.channelid ) from "
+ tablename
+ " t where  feetype='2' and status='DELIVRD' and comefrom not like 'CW%' and mobile in (?)";
PreparedStatement pst = null;
pst = conn.prepareStatement(sql); 
System.out.println("table*******************************" + tablename);
ArrayList<ChannelDao> channellist = new ArrayList<ChannelDao>();
for (int i = 0; i < phnumlist.size(); i++) {
pst.setString(1, phnumlist.get(i));
}
ResultSet rs =pst.executeQuery(sql);
conn.commit();
while (rs.next()) {
ChannelDao channel = new ChannelDao();
channel.setChannelname(rs.getString("name"));
channel.setPhnum(rs.getString("mobile"));
channellist.add(channel);

System.out.println("num*************************"+rs.getString("mobile"));
System.out.println("name*************************"+rs.getString("name"));
}为什么rs取到的结果都为空呢?请各位大虾帮忙,在线等!!

解决方案 »

  1.   

    1.建议lz打印出SQL然后在DB中执行看看,是否是SQL问题。
    2.conn.commit();查询不用commit吧。
    3.pst, rs, conn都没close
      

  2.   

    1.这个貌似直接mobile in ('13516532659', '13516532653')就可以了吧,不用循环的。
    2.循环一次需要pst.addBatch()
      

  3.   

    mobile in (?)//这个里面是多个还是一个,要是多个就不能这么写了 只能拼sql了for (int i = 0; i < phnumlist.size(); i++) {
    pst.setString(1, phnumlist.get(i));
    }
    //这个里面纵使phnumlist有再多的元素,也只能将最后一个元素赋给那个?
      

  4.   

    select distinct t.mobile, m.name from "
    + tablename
    + " t , sms.t_union_info@sms22(姑且当做表名字吧)  m where feetype='2' and status='DELIVRD' and comefrom not like 'CW%' and mobile in (?) and m.unionid=t.channelid
      

  5.   

    ResultSet rs =pst.executeQuery(sql);
    改成
    ResultSet rs =pst.executeQuery();为何循环绑定同一个参数,不解?
      

  6.   

    JDBC的批处理不能加入select语句,否则会抛异常:
    java.sql.BatchUpdateException: Can not issue SELECT via executeUpdate(). 
      

  7.   

    String sql = "select distinct mobile,(select name from sms.t_union_info@sms22 where unionid=t.channelid ) from "
    + tablename
    + " t where feetype='2' and status='DELIVRD' and comefrom not like 'CW%' and mobile in (?)";
    现在的问题是sql语句的问号没有生效
    打印出来的SQL语句是select distinct mobile,(select name from sms.t_union_info@sms22 where unionid=t.channelid ) from sms_mt t where  feetype='2' and status='DELIVRD' and comefrom not like 'CW%' and mobile in (?)
      

  8.   

    好像是这个原因,可是我想把这个参数设置成一个list,我用了pst.setObject(phnumlist)也不好使!
      

  9.   


    你调用的方法不对,应该用execute()
      

  10.   

    1.这个貌似直接mobile in ('13516532659', '13516532653')就可以了吧,不用循环的。
    2.循环一次需要pst.addBatch()
    1. in里n个都可以,你要把list拼成上面样子。
    2.这个方法相当于把没次根据list.get(i)生成的sql存储起来,最后批量处理,2种方法看你用那个。
      

  11.   

    问题解决了,用list.toString()就可以了,呵呵谢谢大家的帮忙!