Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to convert byte array into Blob in java

What is the easiest way to convert byte array into Blob data type in MYSQL with java programming language?

like image 897
androidGuy Avatar asked Jul 12 '11 10:07

androidGuy


People also ask

How do you convert bytes to blobs?

Convert Byte Array to BLOB in Java with an Easy Example Then created a BLOB object initialized with null. Next, I have Converted the file into a Byte array ( byte[] ), stored it into my_byte_array. Finally converted the byte array into BLOB using SerialBlob() method.

Is byte array same as BLOB?

Blob simply means (Binary Large Object) and its the way database stores byte array.

Can we convert byte array to file in Java?

Convert byte[] array to File using Java In order to convert a byte array to a file, we will be using a method named the getBytes() method of String class. Implementation: Convert a String into a byte array and write it in a file.

How do you convert a byte array into a string?

There are two ways to convert byte array to String: By using String class constructor. By using UTF-8 encoding.


2 Answers

Blob blob = connection.createBlob();
blob.setBytes(1, bytes);
like image 176
Bozho Avatar answered Oct 25 '22 09:10

Bozho


Blob fileBlob = new javax.sql.rowset.serial.SerialBlob(byteArray);

like image 26
sarfaraz khan Avatar answered Oct 25 '22 10:10

sarfaraz khan