It depends con how you use your database, direct jdbc, hibernate, ... But basically you have to do following:
- design an entity (and table) to hold the blob.
- don't use BLOB in MySQL is very small, better LONGBLOB.
- create a
java.sql.Blob
from file, usually you have to get an inputstream from file.
- attach blob to hibernate entity, query param, ...
- persist.
I would rather prefer to store files in a different entity/table, and also store file name, size, MIME type, date, ... These attributes will be helpful later.
Use a 1:1 por 1:N relationship between the entity owning the file and the file entity.
Hope it helps!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…