base64图片存储

将图片转换为Base64编码,可以让你很方便地在没有上传文件的条件下将图片插入其它的网页、编辑器中。 这对于一些小的图片是极为方便的,因为你不需要再去寻找一个保存图片的地方。

Base64编码在oracle数据库一般存储为clob。以下是java读取和处理字段的方式供参考。

最近频繁处理clob字段,故集中了几种读取clob字段的方法,仅供参考。

   第一种:

    Clob clob = rs.getClob("report");     String detailinfo ="";     if(clob != null){      detailinfo = clob.getSubString((long)1,(int)clob.length());     }

    第二种:

    Clob clob = rs.getClob("report");     int i = 0;     if(clob != null){      InputStream input = clob.getAsciiStream();      int len = (int)clob.length();      byte by[] = new byte[len];      while(-1 != (i = input.read(by, 0, by.length))){       input.read(by, 0, i);      }      detailinfo = new String(by,"utf-8");     }     

    第三种:

   Clob clob = rs.getClob("report");     String value="";     String line="";     if(clob!=null){            Reader reader=((oracle.sql.CLOB)clob).getCharacterStream();            BufferedReader br=new BufferedReader(reader);            while((line=br.readLine())!=null)            {             value += line +"rn";            }

    } 

 第一种方法代码量少,且能避免中文乱码问题;第二种方法与第一种方法效率差不多,也是常使用的一种方法;第三种方法效率极低,如果数据比较大的话建议不要使用。

三种文档参考文档地址:http://www.thinksaas.cn/group/topic/166610/

原文地址:https://www.cnblogs.com/goodwell21/p/4330438.html