Oracle LONG and LONG RAW Causing “Stream has already been closed” Exception
"
In short: All LONG
or LONG RAW
columns have to be retrieved from the ResultSet
prior to all the other columns.
重要的事:rs.getBytes(3) 一定要放在其它的rs.getXXX的前面。(找了两天,才发现是这个问题,记在这让后来者少走弯路)
"
Like many old databases, Oracle has legacy data types, which are rather nasty to work with in every day SQL. Usually, you don’t run into wild encounters of LONG
and LONG RAW
data types anymore, but when you’re working with an old database, or with the dictionary views, you might just have to deal with LONG
.
These data types are pretty much the same thing as the “newer” LOB representations:
LONG
andCLOB
are somewhat the same thing, except they aren’tLONG RAW
andBLOB
are somewhat the same thing, except they aren’t
Reading LONG or LONG RAW from JDBC causes a “Stream has already been closed” exception
When you have the following schema:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
… you cannot just simply select all columns from JDBC (or other APIs) like this:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
If you’re doing the above, you’ll run into something along the lines of:
Caused by: java.sql.SQLException: Stream has already been closed at oracle.jdbc.driver.LongRawAccessor.getBytes(LongRawAccessor.java:162) at oracle.jdbc.driver.OracleResultSetImpl.getBytes(OracleResultSetImpl.java:708) ... 33 more
The “correct” solution would be, to run the following, instead:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
In short: All LONG
or LONG RAW
columns have to be retrieved from the ResultSet
prior to all the other columns.
重要的事:rs.getBytes(3) 一定要放在其它的rs.getXXX的前面。(找了两天,才发现是这个问题,记在这让后来者少走弯路)
https://blog.jooq.org/2015/12/30/oracle-long-and-long-raw-causing-stream-has-already-been-closed-exception/