title: Read MySQL binary(16) UUID with Java
body: <p>This should be a very simple question, I'm just missing something basic here and I'm having 'one of those days...'
  Cannot use Hibernate or other ORM. Using Java PreparedStatement.</p>
  
  <p>MySQL stuff:</p>
  
  <pre><code>CREATE TABLE `article` (
    `articleID` binary(16) NOT NULL,
    `publisherID` bigint(20) DEFAULT NULL,
    PRIMARY KEY (`articleID`),
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8$$
  
  insert into article ( articleID, publisherID )
  values ( (UNHEX(REPLACE(UUID(),'-',''))), 1111  );
  </code></pre>
  
  <p>Java stuff</p>
  
  <pre><code>PreparedStatement ps = connection.prepareStatement( "select articleID, publisherID from article" );
  ResultSet rs = ps.executeQuery();
  while( rs.next())
  {
    byte[] artIDArr = rs.getBytes( "articleID" );
    UUID artID = UUID.nameUUIDFromBytes( artIDArr );
  }
  
  rs.close();
  ps.close();
  </code></pre>
  
  <p>Now, reading the UUIDs from the database...</p>
  
  <pre><code>    select hex(articleID) from article;
  
  1C711C50E4773873AB1533401E2F420C
  A1FCD341EE9311E297B700FFB00BB509
  A95E06B6EEE611E297B700FFB00BB509
  </code></pre>
  
  <p>But dumping out what I read in the java code:</p>
  
  <pre><code>6c825dc9-c98f-37ab-b01b-416294811a84
  de6337f9-f276-3e30-b9a3-8d9338a1977f
  57ccb5af-1a66-329f-b069-69638e1af24f
  </code></pre>
  
  <p>Now, is this because I'm removing the dashes from the UUID before storing them as binary, and the rehydration is assuming they're there?</p>
  
  <p>What is the correct method for reading a UUID stored as binary(16) in MySql to a Jav UUID object?</p>
  
  <p>Edit: if I change the the preparedStatment query to "select hex(articleID) as articleID..." and read it as a string, it's of course what the DB contains, but UUID throws an exception because the string is missing the dashes...</p>