参考:
create view v_abc
as
select a.user_id,a.user_name,a.user_photo from user_table a
left join (select count(*),user_id as total_friend from friend_table group by user_id)b on a.user_id=b.user_id
where a.user_id in (select TOP 24 member_id from community_member_table
where comm_id='*****' and is_confirm ='true' order by join_time desc)
stmt = con.createStatement();
rs = stmt.executeQuery("select TOP 24 member_id from community_member_table where comm_id='"+comm_id+"' and is_confirm ='true' order by join_time desc");
while(rs.next())
{
userbean = new C_community_memberBean();
userbean.setMember_id(rs.getInt("member_id"));
state = con.createStatement();
rst=state.executeQuery("select user_id,user_name,user_photo from user_table where user_id='"+rs.getInt("member_id")+"'");
if(rst.next())
{
userbean.setUser_id(rst.getInt("user_id"));
user_name=rst.getString("user_name");
if(user_name.length()>8)
{
user_name=user_name.substring(0,8)+"...";
}
userbean.setUser_name(user_name);
userbean.setUser_photo(rst.getString("user_photo"));
//存放下一度朋友个数
st = con.createStatement();
rss=st.executeQuery("select count(*) as total_friend from friend_table where user_id='"+rst.getInt("user_id")+"'");
if(rss.next())
{
if(rss.getInt("total_friend")!=0)
{
numofFriend=String.valueOf(rss.getInt("total_friend"));
}
userbean.setTotal_friend(numofFriend);
}
//////////////////////////
if (rss != null) {
rss.close();
rss=null;
}
if (st != null) {
st.close();
st=null;
}
//////////////////////////
}
///////////////////////////////////
if (rst != null) {
rst.close();
rst=null;
}
if (state != null) {
state.close();
state=null;
}
/////////////////////////////////