加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle LONG and LONG RAW Causing “Stream has already been c

发布时间:2020-12-12 15:15:36 所属栏目:百科 来源:网络整理
导读: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.get

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

CREATE TABLE t_long_raw_and_blob (

id NUMBER(7),

blob1 BLOB,

longx LONG RAW,

blob2 BLOB,

CONSTRAINT pk_t_long_raw_and_blob PRIMARY KEY (id)

);

CREATE TABLE t_long_and_clob (

id NUMBER(7),

clob1 CLOB,

longx LONG,

clob2 CLOB,

CONSTRAINT pk_t_long_and_clob PRIMARY KEY (id)

);

… 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

try (PreparedStatement s = con.prepareStatement(

"SELECT * FROM t_long_raw_and_blob");

ResultSet rs = s.executeQuery()) {

while (rs.next()) {

System.out.println();

System.out.println("ID = " + rs.getInt(1));

System.out.println("BLOB1 = " + rs.getBytes(2));

System.out.println("LONGX = " + rs.getBytes(3));

System.out.println("BLOB2 = " + rs.getBytes(4));

}

}

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

try (PreparedStatement s = con.prepareStatement(

"SELECT * FROM t_long_raw_and_blob");

ResultSet rs = s.executeQuery()) {

while (rs.next()) {

byte[] longx = rs.getBytes(3);

System.out.println();

System.out.println("ID = " + rs.getInt(1));

System.out.println("BLOB1 = " + rs.getBytes(2));

System.out.println("LONGX = " + longx);

System.out.println("BLOB2 = " + rs.getBytes(4));

}

}

In short: AllLONGorLONG RAWcolumns have to be retrieved from theResultSetprior 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/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

Oracle LONG and LONG RAW Causing “Stream has already been closed”Exception

"

In short: AllLONGorLONG RAWcolumns have to be retrieved from theResultSetprior 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 ofLONGandLONG RAWdata types anymore,but when you’re working with an old database,or with the dictionary views,you might just have to deal withLONG.

These data types are pretty much the same thing as the “newer” LOB representations:

  • LONGandCLOBare somewhat the same thing,except they aren’t
  • LONG RAWandBLOBare 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:

    推荐文章
      热点阅读