Easiest way to convert a Blob into a byte array

僤鯓⒐⒋嵵緔 提交于 2019-12-17 09:10:04

问题


what is the easiest way to convert a Blob into a byte array?I am using MYSQL and i want to convert a Blob datatype into a byte array.

Iam using java programming language:)


回答1:


the mySql blob class has the following function :

blob.getBytes

use it like this:

//(assuming you have a ResultSet named RS)
Blob blob = rs.getBlob("SomeDatabaseField");

int blobLength = (int) blob.length();  
byte[] blobAsBytes = blob.getBytes(1, blobLength);

//release the blob and free up memory. (since JDBC 4.0)
blob.free();



回答2:


The easiest way is this.

byte[] bytes = rs.getBytes("my_field");


来源:https://stackoverflow.com/questions/6662432/easiest-way-to-convert-a-blob-into-a-byte-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!