title: How properly work with big data using Swing - performance tips
body: <p>There is an application that I'm basically writing with Swing, JDBC and MySQL.</p>
  
  <ul>
  <li>In DB there are tables like Article, Company, Order, Transaction, Client etc.</li>
  <li>So also there are java classes which describes them. </li>
  <li>User can create,    update, delete information about them.</li>
  </ul>
  
  <p>I give an example of my problem. The article characterizes with id, name, price, company, unit. And when user wants to save new article he chooses the company for this article from the list of all companies. This list in perspective could be really big.</p>
  
  <p>Now I could think of two ways to solve this.</p>
  
  <ol>
  <li><p>When application starts, it connects to the DB and load all the data with which then I will work.</p>
  
  <pre><code>public final class AllInformationController {
  public static final Collection&lt;Company&gt; COMPANIES= new HashSet&lt;&gt;(1_000_000);
  public static final Collection&lt;Article&gt; ARTICLES= new HashSet&lt;&gt;(1_000_000);
  public static final Collection&lt;Order&gt; ORDERS= new HashSet&lt;&gt;(1_000_000);
  public static final Collection&lt;Transaction&gt; transactionsHistory= new HashSet&lt;&gt;(10_000_000);
  //etc...
  private AllInformationController() {}
  }
  </code></pre>
  
  <p>Then if user wants for example to change some Company data (like address or telephone etc.), after doing it the program should update the DB info for that company.</p></li>
  <li><p>The second approach is basically to connect to the database every time user queries or changes some information. So then I will mostly work with <code>ResultSet's</code>.</p></li>
  </ol>
  
  <p>I prefer the second way, but just not sure if it's the best one. Think there should be more productive ways to work with data that could be less expensive.</p>