Storing a byte array into MySQL binary column with JdbcTemplate
<p>I have a MySQL table (simplified):</p>

<pre><code>CREATE TABLE `tokens` (
    `token` BINARY(16) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
</code></pre>

<p>And I try to insert a row like this:</p>

<pre><code>JdbcTemplate jdbcTemplate; // org.springframework.jdbc.core.JdbcTemplate
...
String sql = "INSERT INTO `tokens` (`token`) VALUES (?)";
String token = "123e4567e89b12d3a456426655440000"; // UUID
jdbcTemplate.update(sql, new Object[]{token.getBytes()});
</code></pre>

<p>But I get this exception:</p>

<pre><code>Data truncation: Data too long for column 'token' at row 1  
</code></pre>

<p>What do I do wrong? Thanks.</p>

<p>Edit: see my answer, I missed the hexadecimal conversion (token is an UUID).</p>