views:

121

answers:

0

I need to upload photos into my application and save them to my sqlite database.

I am using the swing filechooser to choose the file then I am converting the file to a fileinputstream and reading the it into bytes.

File file =PictureChooser.getSelectedFile();
FileInputStream fis = new FileInputStream(file);
byte[] photo = new byte[50000];
fis.read(photo);

I am then sending the bytes into the database by :

psmnt.setBytes(3, photo);

where column 3 in my table is a blob

Is this the right way to do it? In what other ways can I implement this? What strategy do I need to use when getting the blob from the database and then trying to conver it back to an image in order to display it?