将 Blob 转换为字节数组的最简单方法 [英] Easiest way to convert a Blob into a byte array

查看:47
本文介绍了将 Blob 转换为字节数组的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 Blob 转换为字节数组的最简单方法是什么?我正在使用 MYSQL,我想将 Blob 数据类型转换为字节数组.

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.

我正在使用 java 编程语言:)

Iam using java programming language:)

推荐答案

mySql blob 类具有以下功能:

the mySql blob class has the following function :

blob.getBytes

blob.getBytes

像这样使用它:

//(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();

这篇关于将 Blob 转换为字节数组的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆