From 505feda055a1f5c59aea53f26680bbbbb0553a0a Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Thu, 20 Jun 2013 18:26:34 +0700 Subject: SQLHelpers.getInt --- src/com/juick/server/UserQueries.java | 68 +++-------------------------------- 1 file changed, 4 insertions(+), 64 deletions(-) (limited to 'src/com/juick/server/UserQueries.java') diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java index 652809d6..e44017fa 100644 --- a/src/com/juick/server/UserQueries.java +++ b/src/com/juick/server/UserQueries.java @@ -367,78 +367,18 @@ public class UserQueries { } public static int getStatsIRead(Connection sql, int uid) { - int ret = 0; - PreparedStatement stmt = null; - ResultSet rs = null; - try { - stmt = sql.prepareStatement("SELECT COUNT(*) FROM subscr_users WHERE suser_id=?"); - stmt.setInt(1, uid); - rs = stmt.executeQuery(); - if (rs.first()) { - ret = rs.getInt(1); - } - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(rs, stmt); - } - return ret; + return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM subscr_users WHERE suser_id=?", uid, 0); } public static int getStatsMyReaders(Connection sql, int uid) { - int ret = 0; - PreparedStatement stmt = null; - ResultSet rs = null; - try { - stmt = sql.prepareStatement("SELECT COUNT(*) FROM subscr_users WHERE user_id=?"); - stmt.setInt(1, uid); - rs = stmt.executeQuery(); - if (rs.first()) { - ret = rs.getInt(1); - } - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(rs, stmt); - } - return ret; + return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM subscr_users WHERE user_id=?", uid, 0); } public static int getStatsMessages(Connection sql, int uid) { - int ret = 0; - PreparedStatement stmt = null; - ResultSet rs = null; - try { - stmt = sql.prepareStatement("SELECT COUNT(*) FROM messages WHERE user_id=?"); - stmt.setInt(1, uid); - rs = stmt.executeQuery(); - if (rs.first()) { - ret = rs.getInt(1); - } - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(rs, stmt); - } - return ret; + return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM messages WHERE user_id=?", uid, 0); } public static int getStatsReplies(Connection sql, int uid) { - int ret = 0; - PreparedStatement stmt = null; - ResultSet rs = null; - try { - stmt = sql.prepareStatement("SELECT COUNT(*) FROM replies WHERE user_id=?"); - stmt.setInt(1, uid); - rs = stmt.executeQuery(); - if (rs.first()) { - ret = rs.getInt(1); - } - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(rs, stmt); - } - return ret; + return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM replies WHERE user_id=?", uid, 0); } } -- cgit v1.2.3