1.用Map查询单条数据。
<select id="" resultType="java.util.Map"> sql语句 </select>
2.将数据强转为blob对象
BLOB blob= (BLOB) map.get("数据列名");
3.将blob对象转成byte[]文章来源:https://www.toymoban.com/news/detail-412330.html
private byte[] blobToBytes(BLOB blob) { BufferedInputStream is = null; try { is = new BufferedInputStream(blob.getBinaryStream()); byte[] bytes = new byte[(int) blob.length()]; int len = bytes.length; int offset = 0; int read = 0; while (offset < len && (read = is.read(bytes, offset, len - offset)) >= 0) { offset += read; } return bytes; } catch (Exception e) { return null; } finally { try { is.close(); is = null; } catch (IOException e) { return null; } } }
4.将byte[] 对象转成String文章来源地址https://www.toymoban.com/news/detail-412330.html
byte[] result = blobToBytes(blob); String swe=new String(result);
到了这里,关于数据库取到blob对象转换成String对象的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!