java - How to save byte data in Blob column of database -



java - How to save byte data in Blob column of database -

i trying execute code in java in somewhere project

class="lang-sql prettyprint-override">insert registered_user (user_image,user_email,phone_no,pin) values ('"+blob+"','"+reqdata.getemail()+"' ,'"+reqdata.getphoneno()+"','"+reqdata.getpin()+"')

i declared blob as

byte[] b=(rqdata.getuserimage());// getter method , has length of 6439==>b.length blob blob=blob=new serialblob(b);

reqdata.getuserimage (pojo class)

byte[] userimage; public byte[] getuserimage() { homecoming userimage; } public void setuserimage(byte[] userimage) { this.userimage = userimage; }

also, others getters , getting values

but getting on console @ execution time statement

class="lang-sql prettyprint-override">insert registered_user (user_image,user_email,phone_no,pin) values ('javax.sql.rowset.serial.serialblob@4dad2f','clientcode17@example.com' ,'null', '123456789')

my question first value in query. have declared user_image column blob in database , here sending blob info object. blob, in case blob has length of 6439, in database saving 30-32 bytes. issue how save bytes in database blob.

thanks in advance.

this line of code converting blob object string:

insert registered_user (user_image,user_email,phone_no,pin) values ('"+blob+"','"+reqdata.getemail()+"' ,'"+reqdata.getphoneno()+"','"+reqdata.getpin()+"')

you need alter insert code utilize prepared statement:

string query = "insert registered_user (user_image,user_email,phone_no,pin) values (?,?,?,?)"; preparedstatement statement = con.preparestatement(query); statement.setblob(1, blob); //continue setting parameters

full illustration here - http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html

java mysql hibernate hql blob

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -