📄 forumstatisticdb.java
字号:
package com.redmoon.forum.util;
import cn.js.fan.db.*;
import java.sql.*;
import cn.js.fan.web.Global;
import org.apache.log4j.Logger;
import cn.js.fan.util.*;
import com.redmoon.forum.person.*;
import com.redmoon.forum.*;
import java.util.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class ForumStatisticDb {
public ForumStatisticDb() {
connname = Global.defaultDB;
}
public int getMemberTotal() {
String sql = "select count(*) from sq_user";
int memberTotal = 0;
Conn conn = new Conn(connname);
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(sql);
rs = conn.executePreQuery();
if (rs.next()) {
memberTotal = rs.getInt(1);
}
} catch (SQLException e) {
Logger.getLogger("load:" + e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {}
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
return memberTotal;
}
public int getAllCount() {
String sql = "select count(*) from sq_message";
int addCount = 0;
Conn conn = new Conn(connname);
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(sql);
rs = conn.executePreQuery();
if (rs.next()) {
addCount = rs.getInt(1);
}
} catch (SQLException e) {
Logger.getLogger("load:" + e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {}
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
return addCount;
}
public int getAddCount() {
String sql = "select count(*) from sq_message where replyid = -1";
int addCount = 0;
Conn conn = new Conn(connname);
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(sql);
rs = conn.executePreQuery();
if (rs.next()) {
addCount = rs.getInt(1);
}
} catch (SQLException e) {
Logger.getLogger("load:" + e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {}
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
return addCount;
}
public int getAddCount(String name){
String sql = "select count(*) from sq_message where name = ? and replyid = -1";
int addCount = 0;
Conn conn = new Conn(connname);
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,name);
rs = conn.executePreQuery();
if (rs.next()) {
addCount = rs.getInt(1);
}
} catch (SQLException e) {
Logger.getLogger("load:" + e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {}
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
return addCount;
}
public int getEliteCount() {
String sql = "select count(*) from sq_message where replyid = -1 and iselite = 1";
int eliteCount = 0;
Conn conn = new Conn(connname);
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(sql);
rs = conn.executePreQuery();
if (rs.next()) {
eliteCount = rs.getInt(1);
}
} catch (SQLException e) {
Logger.getLogger("load:" + e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {}
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
return eliteCount;
}
public int getEliteCount(String name) {
String sql =
"select count(*) from sq_message where name=? and replyid = -1 and iselite = 1";
int eliteCount = 0;
Conn conn = new Conn(connname);
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,name);
rs = conn.executePreQuery();
if (rs.next()) {
eliteCount = rs.getInt(1);
}
} catch (SQLException e) {
Logger.getLogger("load:" + e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {}
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
return eliteCount;
}
public boolean save() throws ErrMsgException {
boolean re = false;
int addCount = 0,eliteCount = 0;
ForumDb fd = new ForumDb();
fd = fd.getForumDb();
fd.setUserCount(getMemberTotal());
fd.setTopicCount(getAddCount());
fd.setPostCount(getAllCount());
re = fd.save();
if (!re)
return re;
UserDb ud = new UserDb();
Vector vt = ud.list();
Iterator ir = vt.iterator();
while(ir.hasNext()){
ud = (UserDb)ir.next();
addCount = getAddCount(ud.getName());
eliteCount = getEliteCount(ud.getName());
ud.setAddCount(addCount);
ud.setEliteCount(eliteCount);
re = ud.save();
if (!re)
break;
}
return re;
}
public boolean save(String name){
int addCount = 0, eliteCount = 0;
boolean re = false;
addCount = getAddCount(name);
eliteCount = getEliteCount(name);
UserDb ud = new UserDb();
ud = ud.getUser(name);
ud.setAddCount(addCount);
ud.setEliteCount(eliteCount);
re = ud.save();
return re;
}
private int id;
private String connname;
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -