打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
把数据库中blob类型转换成String类型
从数据库中读取Blob类型数据后,要转换成String类型,即转换成InputStream,再从InputStream转成byte[],再到String即可。如下:
//把数据库中blob类型转换成String类型
 public String convertBlobToString(Blob blob){
 
  String result = "";
  try {
   ByteArrayInputStream msgContent =(ByteArrayInputStream) blob.getBinaryStream();
   byte[] byte_data = new byte[msgContent.available()];
   msgContent.read(byte_data, 0,byte_data.length);
   result = new String(byte_data);
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return result;
 }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
JAVA将字符串变为输入流
oracle Blob 文件读写
String和InputStream的转换
从Decorator,Adapter模式看Java/IO库(一)
登陆注册使用的验证码(java生成)
BufferedImage缓存图片(data:image/jpg;base64,)转换base64输出与解析
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服