[英]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.