mysql - Java resultset getblob and getobject difference -


i having problem writing / reading bufferedimage java datatype here. when writing seems have no problem inserted data, when reading, have problem using "getobject" method java resultset (for particular reason, method must getobject, can read type of data, , convert after). when inserting bufferedimage datatype mysql using inputstream , has 42559 @ byte array's length, reading using getobject length not 42559 anymore it's size turned 42586, can not read using "imageio.read" method (it returns null)

here insert code:

bytearrayoutputstream baos = new bytearrayoutputstream(); imageio.write((bufferedimage) vals[i], "jpg", baos); inputstream = new bytearrayinputstream(baos.tobytearray()); ps.setbinarystream(i + 1, is); 

here read code:

object set = rs.getobject(i + 1); 

and here convert bufferedimage code:

bytearrayoutputstream b = new bytearrayoutputstream(); objectoutputstream o = new objectoutputstream(b); o.writeobject(set); o.flush(); byte res[] = b.tobytearray(); o.close(); b.close();  system.out.println("cek variabel: " + set.getclass() + "-" + res.tostring() + "-" + res.length); blob blob = kubralib.conn.connselect.getmysqlconn().createblob(); blob.setbytes(1, res); system.out.println("cek variabel: " + blob.tostring());  inputstream = blob.getbinarystream(); system.out.println("cek variabel: " + is.tostring());  bi = imageio.read(is); system.out.println("cek hasil: " + bi.tostring()); <-- returns java.lang.nullpointerexception  is.close(); 

any appreciated :) . , im relatively new stack overflow, if there's mistake in post, apologize :))


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -