简体   繁体   English

读取inputstream时过早到达DB2流的末尾

[英]DB2 end of stream prematurely reached while reading inputstream

Following code: 以下代码:

InputStream imageData=image.getInputStream();
byte[] bytes = ByteStreams.toByteArray(imageData);
pst.setBinaryStream(3, imageData, (int)bytes.length);

gives the following error: 给出以下错误:

com.ibm.db2.jcc.am.SqlException: [jcc][t4][2039][11162][3.57.82] End of stream prematurely reached while reading InputStream, parameter #3. com.ibm.db2.jcc.am.SqlException:[jcc] [t4] [2039] [11162] [3.57.82]在读取InputStream参数#3时过早到达流的末尾。 Remaining data has been padded with 0x0. 剩余数据已用0x0填充。 ERRORCODE=-4225, SQLSTATE=null` ERRORCODE = -4225,SQLSTATE =空

and the DDL which I used to create table is following: 下面是我用来创建表的DDL:

CREATE TABLE ARCH_TRANCHE.UPLOAD_DETAIL (
    SEQ_ID VARCHAR(200) NOT NULL,
    FILE_NAME VARCHAR(140) NOT NULL,
    IMAGE_FILE BLOB(1048576),
    CREATED_DATE TIMESTAMP,
    LAST_MODIFIED_DATE TIMESTAMP,
    FILE_SIZE VARCHAR(20),
    PRIMARY KEY (SEQ_ID,FILE_NAME)
);

I suspect the problem is that you've already read the data by this point in order to obtain bytes ... so when the driver tries to read from imageData , it immediately finds there's no more data to read. 我怀疑问题在于,您已经在这一点上读取了数据以便获取bytes ……因此,当驱动程序尝试从imageData读取imageData ,它会立即发现没有更多的数据可读取。

I suggest you just set the stream without a length: 我建议您将流设置为不长:

pst.setBinaryStream(3, image.getInputStream());

If you can't do that (as per comments) you could extract all the data into a byte array as you're already doing, then wrap that in a ByteArrayInputStream : 如果您不能执行此操作(按照注释),则可以按照已执行的操作将所有数据提取到字节数组中,然后将其包装在ByteArrayInputStream

InputStream imageData = image.getInputStream();
byte[] bytes = ByteStreams.toByteArray(imageData);
pst.setBinaryStream(3, new ByteArrayInputStream(bytes), bytes.length);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MongoSocketReadException:在 Spring 引导连接 MongoDB Atlas 时,过早到达 stream 的末尾 - MongoSocketReadException :Prematurely reached end of stream ,while connecting MongoDB Atlas by Spring Boot MongoSocketReadException:过早到达流末尾(使用 ssl 从 Java 到 Mongo) - MongoSocketReadException: Prematurely reached end of stream (Java to Mongo using ssl) com.mongodb.MongoSocketReadException:过早到达流的结尾 - com.mongodb.MongoSocketReadException: Prematurely reached end of stream mongoDB和Spark:“ com.mongodb.MongoSocketReadException:过早到达流的末尾” - mongoDB & Spark: “com.mongodb.MongoSocketReadException: Prematurely reached end of stream” MongoSocketReadException:过早到达 stream 的末尾(一段时间不活动后) - MongoSocketReadException: Prematurely reached end of stream (after a period of inactivity) 在inputstream.read()中到达流的末尾是什么意思? - What is meant by end of stream reached in inputstream.read()? 将Java应用程序连接到MongoDB-com.mongodb.MongoSocketReadException:已提前到达流的末尾 - Connect Java- Application to MongoDB - com.mongodb.MongoSocketReadException: Prematurely reached end of stream 获取com.mongodb.MongoSocketReadException:过早地到达流MongoDB的末尾 - Getting com.mongodb.MongoSocketReadException: Prematurely reached end of stream- MongoDB MongoClientURI 连接字符串抛出错误“com.mongodb.MongoSocketReadException:过早到达流的末尾” - MongoClientURI connection string throwing error “com.mongodb.MongoSocketReadException: Prematurely reached end of stream” Mongo客户端尝试关闭不存在/创建的连接,并因MongoSocketReadException失败:过早到达流的末尾 - Mongo client trying to close connection that didn't exist/create and fails with MongoSocketReadException: Prematurely reached end of stream
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM