gpt4 book ai didi

java - 从存储过程调用流式传输 blob 数据

转载 作者:太空宇宙 更新时间:2023-11-04 12:18:13 25 4
gpt4 key购买 nike

我正在尝试流式传输从存储过程调用返回的 blob。我正在尝试使用 springs AbstractLobStreamingResultSetExtractor 来执行此操作。

public OutputStream getDocument(final Document doc, final OutputStream outStream) { 

SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(rdcJdbcTemplate)
.withProcedureName(PROC_NAME)
.withCatalogName(CATALOG_NAME)
.withSchemaName(SCHEMA_NAME).declareParameters(new SqlParameter(DOC_ID_PARAM, OracleTypes.VARCHAR),
new SqlOutParameter(OUT_PARAM, OracleTypes.BLOB , new AbstractLobStreamingResultSetExtractor<Object>(){

@Override
protected void streamData(ResultSet rs) throws SQLException,
IOException, DataAccessException {

InputStream blobStream = lobHandler.getBlobAsBinaryStream(rs, 1);
if (blobStream != null){
FileCopyUtils.copy(blobStream, outStream);
}
}
}));

SqlParameterSource in = new MapSqlParameterSource().addValue(DOC_ID_PARAM, doc.getId());

Map<String,Object> out = simpleJdbcCall.execute(in);
return outStream;
}

当我调试这个时,流数据代码永远不会被调用。

我有什么想法可以实现这个吗?

最佳答案

为了 future 的读者,我找到了解决方案

public OutputStream getGlasDocument(final Document doc, final OutputStream outStream) {             

SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(rdcJdbcTemplate)
.withProcedureName(PROC_NAME)
.withCatalogName(CATALOG_NAME)
.withSchemaName(SCHEMA_NAME).declareParameters(new SqlParameter(DOC_ID_PARAM, OracleTypes.VARCHAR),
new SqlOutParameter(OUT_PARAM, OracleTypes.BLOB, null, new SqlReturnType() {

@Override
public Object getTypeValue(CallableStatement cs, int paramIndex,
int sqlType, String typeName) throws SQLException {
try {
Blob blob = cs.getBlob(1);
if (blob != null){
FileCopyUtils.copy(cs.getBlob(1).getBinaryStream(), outStream);
}
} catch (IOException e) {
logger.debug(e.getMessage());
}
return null;
}
}));

SqlParameterSource in = new MapSqlParameterSource().addValue(DOC_ID_PARAM, doc.getId());
simpleJdbcCall.execute(in);
return outStream;
}

关于java - 从存储过程调用流式传输 blob 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39143000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com