Javaはlobフォーマットデータを読みだします。
4606 ワード
lobの中の写真データを読み出すには、clobに格納されているものが何かを確認します。一般的に格納されているbase 64のシリアルです。だからbase 64を例にして、Blobに格納されているものはほとんどが画像データですが、xmlのコンテンツデータもあります。
1クエリーlobフィールドの内容
転載先:https://www.cnblogs.com/fxust/p/7459888.html
1クエリーlobフィールドの内容
Clob clob = rs.getClob(fieldName);
Blob blob = rs.getBlob(fieldName);
2 base 64デコード private byte[] getClobData(Clob clob){
byte[] bt = null;
BASE64Decoder decoder = new BASE64Decoder();
try {
String base64Str = clob.getSubString(1, (int) clob.length());
bt = decoder.decodeBuffer(base64Str);
} catch (Exception e) {
logger.error(" clob ", e);
}
return bt;
}
private byte[] getBlobData(Blob blob) {
BufferedInputStream is = null;
byte[] bt = null;
try {
is = new BufferedInputStream(blob.getBinaryStream());
int bufferSize = (int)blob.length();
bt = new byte[bufferSize];
try {
is.read(bt, 0, bufferSize);
} catch (Exception e) {
logger.error(" Blob ", e);
}
} catch (Exception e) {
logger.error(" Blob ", e);
} finally {
if (is != null) {
try {
is.close();
} catch (Exception e) {
}
is = null;
}
}
return bt;
}
3 lobデータをローカルに保存します。 private void saveDataToLocal(byte[] bt){
try{
String fileName = "E:/test.jpg";
//String fileName = "E:/test.xml"
FileOutputStream out= null;
out= new FileOutputStream(fileName);
out.write(bt, 0, bt.length);
out.close();
}catch(Exception e){
e.printStackTrace();
}
}
転載先:https://www.cnblogs.com/fxust/p/7459888.html