开发者社区 问答 正文

java把字符串存入blob字段

java把字符串存入blob字段怎么存?怎么取出来。

展开
收起
蛮大人123 2016-03-24 16:24:12 2976 分享 版权
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    java.sql.Blob blob = rs.getBlob(2);  
    InputStream in=blob.getBinaryStream();  
    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;  
        }  
    2019-07-17 19:13:01
    赞同 展开评论