title: Inserting Binary data into MySQL (without PreparedStatement's)
body: <p>I'm trying to insert some Binary data into a MySQL database without using prepared statements. The reason for this is that I concatenate thousands of statements into a single insert an run that once. (Exactly how the MySQL dump &amp; import works)</p>
  
  <p>I have tried the following statements, but the are all failing: </p>
  
  <blockquote>
    <p>INSERT INTO my_table VALUES (1,'g=���F|�}X���',2);</p>
    
    <p>INSERT INTO my_table VALUES (1,CAST( 'g=���F|�}X���' AS BINARY),2);</p>
    
    <p>INSERT INTO my_table VALUES (1,CONVERT( 'g=���F|�}X���', BINARY),2);</p>
    
    <p>INSERT INTO my_table VALUES (1,BINARY 'g=���F|�}X���',2)</p>
  </blockquote>
  
  <p>The error I get is:</p>
  
  <blockquote>
    <p><strong>
    com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'binary_data' at row 1</strong></p>
  </blockquote>
  
  <p>The code I use to execute the statement is simply:</p>
  
  <blockquote>
    <p>conn.createStatement().executeUpdate(sql);</p>
  </blockquote>
  
  <p>PreparedStatements work fine (but are too slow in this case)</p>
  
  <p>The actual String I in the database displays a little differet:</p>
  
  <blockquote>
    <p>g=÷óF|¸}X£ì[</p>
    
    <p>Binary View: 67 3d 81 f7 19 f3 46 7c b8 7d 58 8c 10 a3 ec 5b</p>
    
    <p>Java Bytes: 103, 61, -127, -9, 25, -13, 70, 124, -72, 125, 88, -116, 16, -93, -20, 91</p>
  </blockquote>
  
  <p>Could this be something to do with Encoding ?</p>
  
  <p>Any hints much apprecaited,
  Ro</p>