推荐列表数据库操作

一个操作里面选有两个函数体:第一个先在热点表里进行选择,选择了几个给出几个;然后不足45个后面的再根据浏览量选择


public List<CompositionInfo> selectRecommendCompositionList()
{
List<CompositionInfo> compositionlist = new LinkedList<CompositionInfo>();

String sql = "SELECT mp.uucaid, get_uuca_name(mp.uucaid), compositiontype, " +
"compositeid, get_uuca_image(mp.uucaid), get_uuca_counter(mp.uucaid), uuca.datetime " +
"FROM mannual_pops mp,user_upload_composition_activity uuca " +
"WHERE mp.uucaid = uuca.uucaid AND uuca.valid = 1 " +
"ORDER BY mp.popvalue desc " + 
"LIMIT 0, 45";

try {
java.sql.PreparedStatement ps = con.prepareStatement(sql);

ResultSet rs=ps.executeQuery();
while(rs.next())
{
CompositionInfo onecomposition = new CompositionInfo();

onecomposition.setUucaid(rs.getLong(1));
onecomposition.setCompositioname(rs.getString(2));
onecomposition.setType(rs.getInt(3));
onecomposition.setCompositeid(rs.getLong(4));
onecomposition.setImage(rs.getString(5));
onecomposition.setCounter(rs.getLong(6));
onecomposition.setDatetime(getDateFormat(rs.getTimestamp(7)));

compositionlist.add(onecomposition);
}

rs.close();
ps.close();

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}

int count = compositionlist.size();
int leftcount = 45 - count;

sql = "SELECT uucaid, title, compositiontype, compositeid, imageurl, counter, DATETIME " +  
"FROM composition_details " +
"WHERE compositiontype != 3 and valid=1 AND uucaid NOT IN (SELECT uucaid FROM mannual_pops) " +
"ORDER BY counter DESC " +
"LIMIT 0, ?";

try {
java.sql.PreparedStatement ps = con.prepareStatement(sql);

ps.setInt(1, leftcount);

ResultSet rs=ps.executeQuery();
while(rs.next())
{
CompositionInfo onecomposition = new CompositionInfo();

onecomposition.setUucaid(rs.getLong(1));
onecomposition.setCompositioname(rs.getString(2));
onecomposition.setType(rs.getInt(3));
onecomposition.setCompositeid(rs.getLong(4));
onecomposition.setImage(rs.getString(5));
onecomposition.setCounter(rs.getLong(6));
onecomposition.setDatetime(getDateFormat(rs.getTimestamp(7)));

compositionlist.add(onecomposition);
}

rs.close();
ps.close();

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}

return compositionlist;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值