title: How to identify binary data in MySql Database
body: <p>I have a database that stores the location of some data. For simplicity, lets make it</p>
  
  <pre><code>Resource
  ----------
  id (PK)
  resourceLocation
  </code></pre>
  
  <p>In my application, which is written in Java, it has come to a point where all I have is the binary data of the file that is stored at <code>resourceLocation</code>. With just this binary data, I need some way to be able to get this record from the database.</p>
  
  <p>The only thing I can think of is something like this. Add a new column to the <code>Resource</code> table called md5. This will store the MD5 of the file located at resourceLocation.</p>
  
  <pre><code>Resource
  ----------
  id (PK)
  resourceLocation
  md5
  </code></pre>
  
  <p>Then in my code, when all I have is the binary data, I can simply get the MD5 of the data and be able to find the record in the database.</p>
  
  <p>I had a couple of questions about this approach. First, can anyone think of a better way to do it. Second, is there a better hash algorithm than MD5 for this purpose. My concern is that I may wind up with 2 files creating the same MD5 hash. If that happens, my approach fails.</p>