周梦康 发表于 2015-06-03 3533 次浏览 标签 : MysqlJava

想执行的语句是select id,uid,fnum,cont,icons,ts from feed where id in (1,2,3,4)

代码

String getFeedListSql = "select id,uid,fnum,cont,icons,ts from feed where id in (?)";
Connection conn = null;
PreparedStatement statement = null;
try {
    conn = DBUtils.getConnection();
    statement = conn.prepareStatement(getFeedListSql);
    statement.setString(1,"1,2,3,4");
    ResultSet rs = statement.executeQuery();
    while (rs.next()){
        int feedId = rs.getInt(1);
    }
}catch (SQLException e){
    e.printStackTrace();
}finally {
    DBUtils.closeConnection(statement,conn);
}

从查询的结果来看,实际执行的 sql 是select id,uid,fnum,cont,icons,ts from feed where id in (1)

最后我的解决办法就是直接组装这条 SQL

评论列表