您的位置:首页 > 编程语言 > Java开发

JAVA 取 数据库里Blob字段值为字符串的方法

2015-12-22 17:49 435 查看
[java]
view plaincopyprint?

java.sql.Blob blob = rs.getBlob(2);  
InputStream in=blob.getBinaryStream();  

[java]
view plaincopyprint?

public static String getBlob(InputStream in) throws IOException {  
  
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();  
        byte[] data = new byte[4096];  
        int count = -1;  
        while ((count = in.read(data, 0, 4096)) != -1)  
            outStream.write(data, 0, count);  
  
        data = null;  
        String result = new String(outStream.toByteArray(), "gb2312");  
        return result;  
  
    } 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: