Can I read LOB through a closed connection?

I am using wildfly.8.2.0.Final. This server has a connection pool (Oracle). Take a look at the following code:

public ArrayList<HashMap<String, Object>> fetchSome(String query)
        throws OracleQueryProcessorException {
    ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();
    try {
        Context initCtx = new InitialContext();
        DataSource ds = (DataSource) initCtx.lookup(driver);
        try (Connection con = ds.getConnection();
                PreparedStatement stmt = con.prepareStatement(query)) {
            try (ResultSet rs = stmt.executeQuery()) {
                ResultSetMetaData rsmd = rs.getMetaData();
                rs.next();
                HashMap<String, Object> row = new HashMap<String, Object>();
                String name = rsmd.getColumnName(1);
                Object value = rs.getObject(1);
                if (value instanceof Blob) {
                    Blob bl = (Blob) value;
                    if (bl.length() > 0)
                        value = bl.getBinaryStream();
                    else
                        value = null;
                }
                row.put(name, value);
                result.add(row);
            }
        } catch (SQLException e) {
            throw new OracleQueryProcessorException();
        }
    } catch (NamingException e) {
        throw new OracleQueryProcessorException();
    }
    return result;
}

And this is the use of this function:

InputStream is = (InputStream) fetchSome("SELECT BLOB_FIELD FROM TEST WHERE ID = 1").get(0).get("BLOB_FIELD");
            if (is != null) {
                byte[] a = new byte[3];
                is.read(a);
            }

Reading from this thread works !! How it works? The connection is closed (the reason is to use the try-with-resources clause). Reading from this stream does not require a connection from the pool (all connections to the pool are available).

+4
source share
2 answers

fetchSome() Connection, ArrayList. fetchSome Connection ArrayList. , , ArrayList, , Connection, , , .

, , , , , Connection .

0

BLOB? :

  • 4000B (, BLOB - )
  • 2000B ( RAW) - BLOB RAW -
  • 16KB, 32KB
  • - JVM

AFAIK OCI ( C) LOB " ".i.e. BLOB โ€‹โ€‹, . .

v $instance view, , . JDBC Oracle .

, LOB, Connection.createBLOB(), -, . , , Oracle JVM GC, , java. , "".

0

All Articles