Example #1
0
  public Chat getChat(int chatIdno) {
    Connection connection = JDBCManager.getConnection();
    Statement statement = null;
    Chat chat = null;
    try {
      statement = connection.createStatement();
      ResultSet resultSet = statement.executeQuery(selectSQL + chatIdno);

      while (resultSet.next()) {
        chat = new Chat();
        int chatId = resultSet.getInt("chatId");
        String chatText = resultSet.getString("chatText");
        int fromUser = resultSet.getInt("fromUser");

        chat.setChatId(chatId);
        chat.setChatText(chatText);
        chat.setFromUserId(fromUser);
      }
    } catch (Exception exception) {
      exception.printStackTrace();
    } finally {
      try {
        statement.close();
      } catch (Exception exception) {
        exception.printStackTrace();
      }
      JDBCManager.closeConnection(connection);
    }

    return chat;
  }
Example #2
0
  public List<Chat> getChatFrom(int fromUser) {
    Connection connection = JDBCManager.getConnection();
    Statement statement = null;

    List<Chat> chatList = new ArrayList<Chat>();

    try {
      statement = connection.createStatement();
      ResultSet resultSet = statement.executeQuery(fromSelectSQL + fromUser);

      while (resultSet.next()) {
        int chatId = resultSet.getInt("ChatId");
        String chatText = resultSet.getString("ChatText");
        int fromUserId = resultSet.getInt("fromUser");

        Chat chat = new Chat();
        chat.setChatId(chatId);
        chat.setChatText(chatText);
        chat.setFromUserId(fromUserId);

        chatList.add(chat);
      }
      resultSet.close();
    } catch (Exception exception) {
      exception.printStackTrace();
    } finally {
      try {
        statement.close();
      } catch (Exception exception) {
        exception.printStackTrace();
      }

      JDBCManager.closeConnection(connection);
    }

    return chatList;
  }