Esempio n. 1
0
  public void deleteChat(Chat chat) {
    Connection connection = JDBCManager.getConnection();
    PreparedStatement preparedStatement = null;
    try {
      preparedStatement = connection.prepareStatement(deleteSQL);
      preparedStatement.setInt(1, chat.getChatId());
      preparedStatement.executeUpdate();

    } catch (Exception exception) {
      exception.printStackTrace();
    } finally {
      try {
        preparedStatement.close();
      } catch (Exception exception) {
        exception.printStackTrace();
      }
      JDBCManager.closeConnection(connection);
    }
  }
Esempio n. 2
0
  public void saveChat(Chat chat) {
    Connection connection = JDBCManager.getConnection();
    PreparedStatement preparedStatement = null;

    try {
      preparedStatement = connection.prepareStatement(insertSQL);
      preparedStatement.setInt(1, chat.getChatId());
      preparedStatement.setString(2, chat.getChatText());
      preparedStatement.setInt(3, chat.getFromUserId());

      preparedStatement.execute();
    } catch (Exception exception) {
      exception.printStackTrace();
    } finally {
      try {
        preparedStatement.close();
      } catch (Exception exception) {
        exception.printStackTrace();
      }
      JDBCManager.closeConnection(connection);
    }
  }