数据库是Oracle类型的,存入的图片是CLOB类型,现在需要把clob类型的照片再转成照片
MyConn myConn = new MyConn();
    Connection conn = myConn.getConn();
String sql = "select * from cim_citizen_photo ";
Statement stmt = null;
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
String path = "d:/photo";
File file = new File(path);
boolean flag = file.exists();
// 判断新文件夹是否存在,如不存在则新建文件夹
if(!flag){
file.mkdir();
}

while(rs.next()){
String sfzh = rs.getString("personalid");
Clob photo = rs.getClob("photo");
//这里怎么转换??
   }
}
rs.close();
stmt.close();

conn.close();


}
后面的转换不会写了

解决方案 »

  1.   

    http://teddywang.javaeye.com/blog/641136
    看看有合适的没?
      

  2.   

    Blob blob = rs.getBlob(columnName);
    InputStream is = blob.getBinaryStream();
    BufferedImage image = ImageIO.read(is);
    File file = ...;
    ImageIO.write(image,"jpg",file);
      

  3.   

    我这里是clob类型的
    不是blob类型的
      

  4.   

    貌似是先将数据库中的数据读出,然后在硬盘上创建一个xx.jpg的文件,然后再写入吧,这样不就把数据库中的图片存到硬盘上了
      

  5.   

    能从 Clob的 getAsciiStream 生成图片吗? PS. 诅咒你们的 DBA吧!!!
      

  6.   

    哎。。
    存照片时用BASE64Encoder转换了下。
    pic = (new sun.misc.BASE64Encoder()).encode(zp);现在又要转回来,疯掉了
      

  7.   

    呵呵,已经解决了,分享下代码:
    while(rs.next()){
    String sfzh = rs.getString("personalid");
    Clob photo = rs.getClob("photo");
    String pic = photo.getSubString((long)1, (int) photo.length());
                byte[] binary  = (new sun.misc.BASE64Decoder()).decodeBuffer(pic.replaceAll(" ", ""));
                String filename = path+"/"+sfzh+".jpg";

    FileOutputStream fos = null;
    fos = new FileOutputStream(filename);
    fos.write(binary, 0, binary.length);
    fos.close(); }
      

  8.   

    楼主,你怎么用CLOB方式存图片的