cancel
Showing results for 
Search instead for 
Did you mean: 

Insert/Select Long Binary in UltraLiteJ DB

Former Member
3,702

I would like to insert an image into ultralitej-db (Android) and later get it from db to display it again.

I'm able to insert and select it from db but the displayed image is all black.

insert-code:

ps = mConn.prepareStatement(query);
        OutputStream os = ps.getBlobOutputStream(1);

        os.write(photo);

        success = ps.execute();
        ps.close();


select-code:

rs.first();
                            InputStream is = rs.getBlobInputStream("Picture");
                            ByteArrayOutputStream buffer = new ByteArrayOutputStream();

                            int nRead;
                            byte[] bytes = new byte[16384];

                            try {
                                while ((nRead = is.read(bytes, 0, bytes.length)) != -1) {
                                  buffer.write(bytes, 0, nRead);
                                }

                            buffer.flush();
                            is.close();

                            } catch (IOException e) {
                                e.printStackTrace();
                            }


UPDATE it seems that the insert is wrong. i selected other images which are already stored in the db. they are displayed correctly.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

better late than never. i found the solution for my problem. it was a converting/format thing with jpeg.

i used mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos); and got the whole black image. then i tried mBitmap.compress(Bitmap.CompressFormat.PNG, 100, bos); and it works.

thanks to all who gave me advices to solve the problem

Answers (0)