/*
* 计算某类别新闻的总数
*/
/*
* 第一个是指你SQL语句中的第几个参数,第二个是要设置的值。比如:
SQL语名如下:
Select * From tableName Where id=? And Name=?
则:
pstmt.setInt(1,100)就表示此处id=100,而如果是这样:
pstmt.setString(2,"abc")就表示此处Name="abc"。
*/
public int getTotalByCategoryId(int categoryId) {
DBConnect dbc = null;
int newsCount = 0;
ResultSet rs = null;
try {
dbc = new DBConnect();
dbc
.prepareStatement("SELECT count(*) FROM news WHERE categoryid = ?");
dbc.setInt(1, categoryId);
rs = dbc.executeQuery();
if (rs.next())
newsCount = rs.getInt(1);
} catch (Exception e) {
System.err.println(e);
} finally {
try {
if (rs != null) {
rs.close();
}
dbc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return newsCount;
}
posted on 2006-10-30 20:20
dragon 阅读(2861)
评论(0) 编辑 收藏 所属分类:
jsp