数据库是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();
}
后面的转换不会写了
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();
}
后面的转换不会写了
看看有合适的没?
InputStream is = blob.getBinaryStream();
BufferedImage image = ImageIO.read(is);
File file = ...;
ImageIO.write(image,"jpg",file);
不是blob类型的
存照片时用BASE64Encoder转换了下。
pic = (new sun.misc.BASE64Encoder()).encode(zp);现在又要转回来,疯掉了
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(); }