title: How do I make my function for testdata for my database faster?
body: <p>I want to create testdata and have written a function for storing the products, my product generators generate in my database.</p>
  <p>The plan is to create about 10,000,000 products or more for testing purposes.</p>
  <p>I want to check every time before I insert a product, if the same product name exists.</p>
  <p>If it does, the product isn't stored in the database.
  I know that the performance issue is the checking if the products exist, which takes longer and longer the more products are in the database. But there is no other way, I know, how I can improve this issue.
  I may use indexes, but I don't know how to in this scenario.
  If you have other ideas how to improve performance please feel free to comment your ideas.</p>
  <p>tldr: I want to create testdata but it does take too long because it is checking if the products already exist. Want to improve performance.</p>
  <p>Here is my code:</p>
  <pre><code>   public String insertProdukt(String name, Double preis, Integer kat_id) throws SQLException, ClassNotFoundException {
      Connection connection = ConnectionUtils.createNewConnection();
      // does the product exist?
      Statement statement = connection.createStatement();
      ResultSet resultSet = statement.executeQuery(&quot;select * from pro_produkte where pro_name=\&quot;&quot; + name + &quot;\&quot; AND pro_preis=\&quot;&quot; + preis + &quot;\&quot; AND pro_kat_id=\&quot;&quot; + kat_id + &quot;\&quot;&quot;);
  
      if (resultSet.next()) {
          //it does exist
          System.out.println(&quot;Produkt: &quot; + resultSet.getString(&quot;pro_name&quot;) + &quot; existiert bereits&quot;);
      } else {
          //it dosen't -&gt; insert into database
          String sql = &quot;Insert INTO pro_produkte (pro_name, pro_preis, pro_kat_id)&quot;
                  + &quot;VALUES (\&quot;&quot; + name + &quot;\&quot;, \&quot;&quot; + preis + &quot;\&quot;, \&quot;&quot; + kat_id + &quot;\&quot;)&quot;;
          statement.executeUpdate(sql);
          System.out.println(&quot;Produkt: &quot; + name + &quot; erstellt&quot;);
  
      }
      resultSet.close();
      statement.close();
      connection.close();
      return null;
  }
  </code></pre>
  <p>Thanks!</p>