posted 10 years ago
Hi Rosu,
There are various ways to store binary data in DB tables:
Convert the data to binary, and then encode it to Base64 encoding. Apache provides a ready-made implementation for Base64 encoding-decoding.
Pros: Base64 is pure char format. So this data can be stored in any varchar column. Also, this is easier to manage than blob.
Cons: When a byte-buffer is converted to Base64 format, it's size is increased (typically by 33%) - and varchar column generally has limit of 4000 chars.
Store data as blob.
Pros: Data can be directly stored as binary. No need to do any encoding-decoding. Also, large objects can be stored (e.g. zipped files etc.)
Cons: If original data is not in byte format, then char-to-byte conversion has to be done manually - which is more error prone than Base64 encoding-decoding.
There is a third way of doing it via RAW datatype (which is supported on Oracle) - however, I'm not sure if that is supported on MySql.
I hope this helps.
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)