Esempio n. 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;
  }
Esempio n. 2
0
 public void updateChat(Chat chat) {
   Connection connection = JDBCManager.getConnection();
   PreparedStatement preparedStatement = null;
   try {
     preparedStatement = connection.prepareStatement(updateSQL);
     preparedStatement.setString(1, chat.getChatText());
     preparedStatement.setInt(2, chat.getFromUserId());
     preparedStatement.setInt(3, chat.getChatId());
     preparedStatement.executeUpdate();
   } catch (Exception exception) {
     exception.printStackTrace();
   } finally {
     try {
       preparedStatement.close();
     } catch (Exception exception) {
       exception.printStackTrace();
     }
     JDBCManager.closeConnection(connection);
   }
 }
Esempio n. 3
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;
  }