From 378b014b82158d06a6ee986cb7522a04bc59f5bc Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Tue, 16 Jul 2013 04:07:15 +0700 Subject: getUsersByName, getUsersByJID --- src/com/juick/server/UserQueries.java | 53 +++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 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 f0c5a57f..f1b235af 100644 --- a/src/com/juick/server/UserQueries.java +++ b/src/com/juick/server/UserQueries.java @@ -68,7 +68,7 @@ public class UserQueries { return uid; } - public static com.juick.User getUserByNick(Connection sql, String username) { + public static com.juick.User getUserByName(Connection sql, String username) { com.juick.User user = null; PreparedStatement stmt = null; @@ -90,13 +90,36 @@ public class UserQueries { return user; } + public static ArrayList getUsersByName(Connection sql, ArrayList unames) { + ArrayList users = new ArrayList(); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT id,nick FROM users WHERE nick IN (" + Utils.convertArrayString2String(unames) + ")"); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + com.juick.User user = new com.juick.User(); + user.UID = rs.getInt(1); + user.UName = rs.getString(2); + users.add(user); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + return users; + } + public static ArrayList getUsersByID(Connection sql, ArrayList uids) { ArrayList users = new ArrayList(); PreparedStatement stmt = null; ResultSet rs = null; try { - stmt = sql.prepareStatement("SELECT id,nick FROM users WHERE id IN (" + Utils.convertArray2String(uids) + ")"); + stmt = sql.prepareStatement("SELECT id,nick FROM users WHERE id IN (" + Utils.convertArrayInt2String(uids) + ")"); rs = stmt.executeQuery(); rs.beforeFirst(); while (rs.next()) { @@ -114,6 +137,30 @@ public class UserQueries { return users; } + public static ArrayList getUsersByJID(Connection sql, ArrayList jids) { + ArrayList users = new ArrayList(); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT users.id,users.nick,jids.jid FROM users INNER JOIN jids ON jids.user_id=users.id WHERE jids.jid IN (" + Utils.convertArrayString2String(jids) + ")"); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + com.juick.User user = new com.juick.User(); + user.UID = rs.getInt(1); + user.UName = rs.getString(2); + user.JID = rs.getString(3); + users.add(user); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + return users; + } + public static String getJIDbyUID(Connection sql, int uid) { return SQLHelpers.getString(sql, "SELECT jid FROM jids WHERE user_id=? AND active=1", uid); } @@ -307,7 +354,7 @@ public class UserQueries { PreparedStatement stmt = null; ResultSet rs = null; try { - stmt = sql.prepareStatement("SELECT user_id FROM bl_users WHERE bl_user_id=? and user_id IN (" + Utils.convertArray2String(uids) + ")"); + stmt = sql.prepareStatement("SELECT user_id FROM bl_users WHERE bl_user_id=? and user_id IN (" + Utils.convertArrayInt2String(uids) + ")"); stmt.setInt(1, visitor); rs = stmt.executeQuery(); rs.beforeFirst(); -- cgit v1.2.3