关闭数据库连接后,从Oracle DB读取CLOB [英] Reading a CLOB from Oracle DB after the DB connection is closed

查看:372
本文介绍了关闭数据库连接后,从Oracle DB读取CLOB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在审查的一个Java类中,我看到以下代码

In one of the Java classes I am reviewing I see the following code

private oracle.sql.CLOB getCLOB() {
    oracle.sql.CLOB xmlDocument = null;
    CallableStatement cstmt = null;
    ResultSet resultSet = null;
    Connection connection = null;

    try {
        connection = Persistence.getConnection();
        cstmt = connection.prepareCall("{call pkg.proc(?,?)}");
        cstmt.registerOutParameter(1, OracleTypes.CURSOR);
        cstmt.setString(2, id);
        cstmt.execute();
        resultSet = (ResultSet)cstmt.getObject(1);

        if (resultSet.next()) {
            xmlDocument = ((OracleResultSet) resultSet).getCLOB(1);
        }
    } finally {
        Persistence.closeAll(resultSet, cstmt, connection);
    }
    return xmlDocument;
 }

getCLOB()返回的oracle.sql.CLOB在另一个方法中读取:

The oracle.sql.CLOB that is returned by getCLOB() is read in another method:

 private void anotherMethod() {
    ...
    oracle.sql.CLOB xmlDocument = getCLOB();
    clobLength = xmlDocument.length();
    chunkSize = xmlDocument.getChunkSize();
    textBuffer = new char[chunkSize];

    for (int position = 1; position <= clobLength; position += chunkSize) {
        charsRead = xmlDocument.getChars(position, chunkSize, textBuffer);
        outputBufferedWriter.write(textBuffer, 0, charsRead);
    }
    ...

 }

我是这个项目的新手,这里的人说这段代码正在工作.我不了解在关闭基础数据库连接后如何读取CLOB(据我的理解是参考).我想念什么?

I am new to this project and the folks here say this code is working. I don't understand how we can read a CLOB (which, in my understanding, is a reference) after the underlying database connection is closed. What am I missing?

要注意的另一点是,此代码正在应用服务器中运行. Persistence.getConnection()从数据源(最可能使用连接池)获取连接.我想知道数据库连接返回到连接池后是否使用.

Another point to note is that this code is running in an app server. Persistence.getConnection() gets the connection from a data source (most probably with a connection pool). I wonder if the database connection is used after it is returned to the connection pool.

将连接返回池后使用连接可能不是原因.该应用程序服务器是Oracle的Glassfish服务器 Websphere ,我希望它们能够防止此类使用.

Using the connection after it was returned to the pool might not be the cause. The app server is Oracle's Glassfish server Websphere and I am hoping they would guard against such usage.

推荐答案

JDBC驱动程序将预选择的LOB提取到结果集中.读取API可以使用预取缓冲区 没有连接.缓冲区大小由oracle.jdbc.defaultLobPrefetchSize参数指定,默认值为4000.

JDBC driver prefetches LOBs selected into a result set. Read API can use prefetch buffers without connection. Buffer size specified by oracle.jdbc.defaultLobPrefetchSize parameter with default 4000.

这篇关于关闭数据库连接后,从Oracle DB读取CLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆