Sunday, January 13, 2008

Blob, Binary and other Java hardships

So, what's the difference between

byte[] fred = {-122, -97, -120, 111};

System.out.println(fred.toString());
System.out.println(new String(fred));

Well, you would same they should print the same right. Sadly wrong. So this took me a day of debugging to find out why my Fact table was producing the wrong results from the Data Warehouse queries. So I tried
  • Stuffing the data into a BLOB, well its binary after all. Broke all the joins over this column
  • Converting to Hex but got different results for the same byte[] value
  • Converting to a Binary String (i.e. 1's and 0's), but seemed horribly inefficient
  • Converting to a String, like Hex got different results for the same byte[] value and was unprintable through the mysql prompt
So I ended up keeping the value as a byte[] in the Java code and then stuffing the value in a Binary column... easy when you know how. So I just need to reconcile the values I am now getting.

No comments: