我正在尝试从 Oracle SQL 表中检索 CLOB。 Clob 大约有 25MB。我收到一个错误: 警告:已解决 [org.springframework.web.util.NestedServletException:处理程序调度失败;嵌套异常是 java.lang.OutOfMemoryError: Java heap space] 有什么方法可以检索文件。 使用 Springboot 的任何其他替代方法。
代码如下:
public byte[] getData(String task){
StringBuilder sb = new StringBuilder();
sb.append("select OUTPUT_file from tablea where task = ?");
byte[] fileBytes = jdbcTemplate.query(sb.toString(), new Object[]{task}, (rs) ->{
if(rs.next()){
byte[] resByteArry =new byte[0];
Clob clob = rs.getClob("OUTPUT_file");
resByteArry =getByteArrayByStream(clob.getAsciiStream());
return resByteArry;
}else {
return new byte[0];
}
});
return fileBytes;
}
private byte[] getByteArrayByStream(InputStream ins){
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
int length =0;
while( (length = ins.read(buffer,0,buffer.length)) !=-1){
out.write(buffer,0,length);
}
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return out.toByteArray();
}