我有一个返回Blob的pl / sql过程。这就是我所说的:
CallableStatement cstmt = null;
Blob blob = null;
cstmt = con.prepareCall("{? = call billing.PREQUEST.GetAttachment(?)}");
cstmt.registerOutParameter(1,
OracleTypes.BLOB);
cstmt.setInt(2, id);
cstmt.execute();
blob = cstmt.getBlob(1);
现在我想从blob获取文件名。我怎么能这样做?
答案 0 :(得分:1)
BLOB
列不存储文件名。您需要添加一个类型为VARCHAR2
的单独列,用于存储原始文件名。
如果您处理已经包含大量数据的现有数据库,那么您运气不好。文件名未存储,无法恢复。
答案 1 :(得分:0)
您需要将Blob
更改为File
。试试这段代码:
Blob blob = cstmt.getBlob(column);
InputStream in = blob.getBinaryStream();
OutputStream out = new FileOutputStream("OutputFile");
byte[] buff = new byte[4096];
int length = 0;
while ((length = in.read(buff)) != -1) {
out.write(buff, 0, length );
}
// From here, read in the File and just call "getName()"
// Also, make sure to call to close out and in