Subject | Re: InputStream closes when prepared statement is closed. |
---|---|
Author | Roman Rokytskyy <rrokytskyy@yahoo.co.uk> |
Post date | 2003-01-29T10:04:43Z |
> I am using the JDBC driver (interclient.jar for jdk1.3) for FirebirdAccording to the specification ResultSet is implicitly closed when
> and noticed that when I extract a blob to an Inputstream, the stream
> is closed when I close the PreparedStatement. For instance,
>
> ptmnt = con.prepareStatement("Select foo from bar");
> rs = pstmnt.executeQuery();
> InputStream is = rs.getBinaryStream("foo");
> rs.close();
> pstmnt.close(); <---- At this point the InputStream "is" is also
> closed.
>
> This does not happen with Oracle or IBM, so I have had to adjust the
> server facade for Firebird so that the Object is deserialised before
> the statement is closed.
statement that created it is closed. Closing result set means
releasing any external resources hold by a result set and input
stream is one of such resources. But there is even more strict
requirement in the specification for ResultSet.getBinaryStream(int)
method:
"Note: All the data in the returned stream must be read prior to
getting the value of any other column. The next call to a getXXX
method implicitly closes the stream. Also, a stream may return 0 when
the method InputStream.available is called whether there is data
available or not."
So, behaviour of Oracle and IBM JDBC drivers is incorrect according
to the specification.
> I would rather hold on to the stream and deserialise when required.You can copy stream into array of bytes and keep it in memory. But I
think deserializing would be faster solution unless you plan to
deserialize stream in another class loader.
Best regards,
Roman Rokytskyy