db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-5090) Retrieving BLOB fields sometimes fails
Date Tue, 15 Mar 2011 22:12:29 GMT

    [ https://issues.apache.org/jira/browse/DERBY-5090?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13007227#comment-13007227
] 

Knut Anders Hatlen commented on DERBY-5090:
-------------------------------------------

Hi Unai,

JDBC's definition of ResultSet.getBinaryStream() can be found here:
http://download.oracle.com/javase/6/docs/api/java/sql/ResultSet.html#getBinaryStream(java.lang.String)

It says:

,----
| 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 getter
| method implicitly closes the stream.
`----

So it seems like the specification demands that the stream is closed
by the calls to getShort() and getString() between the calls to
getBinaryStream() and read(). And I suppose that the implicit closing
of the stream is why the IOException is raised by read().

But although the described behaviour appears to match the
specification, I think it would be good if the IOException had a
message text saying the stream was closed, rather than just having a
null message. I think we should keep this bug report open until we
have a better error message.

> Retrieving BLOB fields sometimes fails
> --------------------------------------
>
>                 Key: DERBY-5090
>                 URL: https://issues.apache.org/jira/browse/DERBY-5090
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC, Miscellaneous
>    Affects Versions: 10.7.1.1
>         Environment: JDBC derby embedded driver
>            Reporter: Unai Vivi
>              Labels: BLOB, Ordering, exception, null, order, read
>
> This is my first issue report, so please be understanding if I'm posting the wrong thing,
in the wrong place or in the wrong way. I just want to help. :)
> While iterating through a ResultSet, when accessing a BLOB field to read its contents
via an InputStream, I noticed that:
> - if the current ResultSet's has been "warmed up" by retrieving another column first,
everything it's fine;
> - if, on the other hand, you first-thing access the BLOB (and read other columns later),
then upon reading the first byte out the InputStream bound to the BLOB field (ResultSet.getBinaryStream("col_name"))
an IOException is thrown (and IOException's getMessage() method returns null).
> Following is an example, taken from a real application. The two code segments only differ
in the fact that a SMALLINT & VARCHAR read is done before/after the BLOB read.
> --Working snippet--
> [...]
>                     icRelPath[i] = "imm" + File.separator + "ic" + "_" + rs.getShort("setIcone")
+ "_" + i + "." + rs.getString("estensione");
>                     AutoCloseInputStream acis = new AutoCloseInputStream(rs.getBinaryStream("ic"
+ i));
>                     if (rs.wasNull())
>                         icRelPath[i] = null;
>                     else
>                     {
>                         //icRelPath[i] = "imm" + File.separator + "ic" + "_" + rs.getShort("setIcone")
+ "_" + i + "." + rs.getString("estensione");
>                         BufferedInputStream bis = new BufferedInputStream(acis);
>                         int b = bis.read();//READS FINE
> [...]
> --Broken snippet--
> [...]
>                     //icRelPath[i] = "imm" + File.separator + "ic" + "_" + rs.getShort("setIcone")
+ "_" + i + "." + rs.getString("estensione");
>                     AutoCloseInputStream acis = new AutoCloseInputStream(rs.getBinaryStream("ic"
+ i));
>                     if (rs.wasNull())
>                         icRelPath[i] = null;
>                     else
>                     {
>                         icRelPath[i] = "imm" + File.separator + "ic" + "_" + rs.getShort("setIcone")
+ "_" + i + "." + rs.getString("estensione");
>                         BufferedInputStream bis = new BufferedInputStream(acis);
>                         int b = bis.read();//THROWS IOException WITH A null ERROR MESSAGE
STRING
> [...]

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message