1.用Map查询单条数据。

<select id="" resultType="java.util.Map">
    sql语句
</select>

2.将数据强转为blob对象

BLOB blob= (BLOB) map.get("数据列名"); 

3.将blob对象转成byte[]

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

byte[] result = blobToBytes(blob);
String swe=new String(result);
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐