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取到的结果都为空呢?请各位大虾帮忙,在线等!!
+ 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取到的结果都为空呢?请各位大虾帮忙,在线等!!
2.conn.commit();查询不用commit吧。
3.pst, rs, conn都没close
2.循环一次需要pst.addBatch()
pst.setString(1, phnumlist.get(i));
}
//这个里面纵使phnumlist有再多的元素,也只能将最后一个元素赋给那个?
+ 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
改成
ResultSet rs =pst.executeQuery();为何循环绑定同一个参数,不解?
java.sql.BatchUpdateException: Can not issue SELECT via executeUpdate().
+ 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 (?)
你调用的方法不对,应该用execute()
2.循环一次需要pst.addBatch()
1. in里n个都可以,你要把list拼成上面样子。
2.这个方法相当于把没次根据list.get(i)生成的sql存储起来,最后批量处理,2种方法看你用那个。