public Vector<Message> getInboxMessages(String username, int type) { if (type == 4) username = "******"; ResultSet rs = con.queryDB( "SELECT * FROM " + MESSAGES + " WHERE toName = \"" + username + "\" AND messageType = " + type + " ORDER BY timeStamp DESC"); Vector<Message> inbox = new Vector<Message>(); try { while (rs.next()) { inbox.add( new Message( rs.getString("fromName"), username, rs.getString("message"), rs.getInt("messageType"), rs.getTimestamp("timeStamp"))); } } catch (SQLException e) { throw new RuntimeException("SQLException in MessageDatabase::getInboxMessages"); } return inbox; }
/* * Returns a Vector representing all messages in the user's outbox. The most recent * messages are at the beginning, and the oldest ones are at the end. */ public Vector<Message> getOutboxMessages(String username) { ResultSet rs = con.queryDB( "SELECT * FROM " + MESSAGES + " WHERE fromName = \"" + username + "\" ORDER BY timeStamp DESC"); Vector<Message> outbox = new Vector<Message>(); try { while (rs.next()) { outbox.add( new Message( username, rs.getString("toName"), rs.getString("message"), rs.getInt("messageType"), rs.getTimestamp("timeStamp"))); } } catch (SQLException e) { throw new RuntimeException("SQLException in MessageDatabase::getOutboxMessages"); } return outbox; }