What is the easiest way to convert byte array into Blob data type in MYSQL with java programming language?
- Have you tried anything yourself? Googling "java convert byte[] to sql.blob" gives a lot of hits ..Wivani– Wivani2011-07-12 10:39:30 +00:00Commented Jul 12, 2011 at 10:39
- well i have been googling for some time now,thats y i finally thought of posting it here.I did convert byte array to a serialblob bt had a problem converting it back to a bytearray since my table column was of type blob.I am here to get a proper way of converting a byte array into a blob,thanks:)androidGuy– androidGuy2011-07-12 10:45:55 +00:00Commented Jul 12, 2011 at 10:45
Add a comment |
3 Answers
Blob blob = connection.createBlob(); blob.setBytes(1, bytes); 2 Comments
Bozho
well, you need the connection object, obviously :)
Majid Azimi
setBytes() returns number of bytes written. Should we write it inside loop for partial write? or single line of code will suffice? I have a 50KB byte[] all in memory which I want to save.You may try this one, if you are using hibernate.. Possibly the easiest way! :)
Blob blob = Hibernate.createBlob(bytes); 1 Comment
Adri w Ukraine
this is deprecated. See docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/…