当前页面: 开发资料首页 → JSP 专题 → 这种方法可行不?
这种方法可行不?
摘要: 这种方法可行不?
public Vector allNews() {
DBConnect dbc = null;
Vector allNewsVector = new Vector();
try{
dbc = new DBConnect();
dbc.prepareStatement("SELECT * FROM news order by hits desc");
rs = dbc.executeQuery();
while(rs.next()){
News news = new News();
news.setID(rs.getInt("id"));
news.setTopic(rs.getString("topic"));
news.setBody(rs.getString("body"));
news.setHits(rs.getInt("hits"));
news.setAdddate(rs.getString("adddate"));
news.setAdduser(rs.getString("adduser"));
news.setRootID(rs.getInt("rootid"));
news.setPic(rs.getString("pic"));
allNewsVector.add(news);
}
}catch(Exception e){
System.err.println("error:"+e);
}finally{
try{
dbc.close();
}catch(Exception e){
e.printStackTrace();
}
}
return allNewsVector;
}
如果新闻的条数很多呢?
如果不是需要所有新闻的话,可以在sql语句里用top x来控制取得记录的数量
按照你每次想展现给客户的数据量分页
就是要全部新闻!
那你问什么…………
你的代码84没错么……
除了用Vector
还可以用哈子???