日期:2014-05-18 浏览次数:20662 次
public List<Articles> query(int indexone, int indextwo, String titleonetitle) {
String sqlstr = "SELECT articles.id,articles.title,MAX(clickcounts) AS clickcounts,articles.img FROM articles WHERE "
+ "forid IN(SELECT titletwo.`ID` FROM titletwo WHERE forid IN (SELECT id FROM titleone WHERE titletab=?)) GROUP BY clickcounts desc limit ?,?;";
mysqlcon = Mysqlcon.getInstacce();
Connection connection = null;
try {
connection = mysqlcon.getConnection();
} catch (SQLException e1) {
System.err.println("获取连接桥失败..");
e1.printStackTrace();
}
List<Articles> list = new ArrayList<>();
try {
ps = (PreparedStatement) connection.prepareStatement(sqlstr);
ps.setString(1, titleonetitle);
ps.setInt(2, indexone);
ps.setInt(3, indextwo);
ResultSet rs = (ResultSet) ps.executeQuery();
while (rs.next()) {
Articles articles = new Articles();
articles.setId(rs.getInt(1));
articles.setTitle(rs.getString(2));
articles.setClickcounts(rs.getInt(3));
articles.setImg(rs.getString(4));
list.add(articles);
}
timer = new Timer(true);
timer.schedule(new TimerTask() {
public void run() {
这里会报错,说的是必须设置rs,connection为final类型
mysqlcon.free(rs, ps, connection);
}
}, 0, 5000);
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}