java - getBlob() crashes if blob is over 2MB, substr method does not work -


i trying use getblob method retrieve picture byte[].

however, if the blob on 2mb noticed crash.

i found article stating use substr function in segments not working.

heres sample, it's quite rough.

                      if( size > 2000000 ) {                         c = db.rawquery("select substr(picture, 1, 1000000)  pics id = 1, null);                         if( c.movetofirst() ) {                             byte[] image1, image2, image3, image4, image5;                             image2 = c.getblob(0);                             c = db.rawquery("select substr(picture, 1000001, 2000000)  pics id = 1, null);                             if( c.movetofirst() ) {                                 image3 = c.getblob(0);                                 image4 = concatenatebytearrays(image2, image3);                                 c = db.rawquery("select substr(picture, 2000001, 3000000) pics id = 1, null);                                 if( c.movetofirst() ) {                                     image5 = c.getblob(0);                                     image1 = concatenatebytearrays(image4, image5);                                     bytearrayinputstream inputstream = new bytearrayinputstream(image1);                                     bitmap bitmap = bitmapfactory.decodestream(inputstream);                                     image.setimagebitmap(bitmap);                                 }                             }                         } 

any regarding appreicated.

thanks.

this example show how read data blob column

class.forname("your_db_drier"); connection conn = drivermanager.getconnection(url, username, password);

string sql = "select name, description, image pictures "; preparedstatement stmt = conn.preparestatement(sql); resultset resultset = stmt.executequery(); while (resultset.next()) {   string name = resultset.getstring(1);   string description = resultset.getstring(2);   file image = new file("d:\\java.gif");   fileoutputstream fos = new fileoutputstream(image);    byte[] buffer = new byte[512]; // as increase array                //   increase performance of data reading.    inputstream = resultset.getbinarystream(3);   while (is.read(buffer) > 0) {     fos.write(buffer);   }   fos.close(); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -