Re: jdbc1 AbstractJdbc1Statement setObject() does not work

From: Barry Lind <blind(at)xythos(dot)com>
To: Paulo Eduardo Azevedo Silveira <peas(at)linux(dot)ime(dot)usp(dot)br>
Cc: pgsql-jdbc(at)postgresql(dot)org, Gilmar Gimenes Rodrigues <rgil(at)linux(dot)ime(dot)usp(dot)br>
Subject: Re: jdbc1 AbstractJdbc1Statement setObject() does not work
Date: 2002-11-20 08:29:31
Message-ID: 3DDB47EB.8010302@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Paulo,

There are a couple of problems with what you are suggesting here. First
there is no way to know the length of an input stream. The available()
method isn't supposed to return the entire length of the data stream but
only what is currently available. Thus using the result of available()
as what you pass in to setBinaryStream() will not work. Which means it
isn't possible to call setBinaryStream from setObject since you don't
know the length ahead of time.

The second problem is that the JDBC spec explicitly states the following:

Section 14.2 (last paragraph):
Note that it is not possible to send or receive Java input streams
using the getObject or setObject methods. You must explicitly use
PreparedStatement.setXXXStream or Result- Set.getXXXStream to transfer a
value as a stream.

thanks,
--Barry

Paulo Eduardo Azevedo Silveira wrote:
> Hello!
>
> Inside of public void setObject(int parameterIndex, Object x) throws
> SQLException, there is NO if to see if it X is instanceof
> InputStream. This was crashing my application when trying to pass a
> ByteArrayInputStream as argument to setObject, since it does no fit in any
> of the instanceofs, and get into the alst line, where it is serialized
> (and a completely strange exception message is thrown from other point)
>
> http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java?rev=1.13&content-type=text/x-cvsweb-markup
>
> I ve made a CVS patch for it, if anyone is interested in these couples of
> lines. It is just a if-instanceof-InputStream that delegates the setObject
> to setBinaryStream with lenght equals to inputstream.available()
>
> One more thing: all those imports something.* make really hard for the
> other coders to find where the classes are being imported from. Sorry to
> be "picky".
>
> Thanks a lot for your attention.
>
> ---------------------------------------
> Paulo Silveira (www.paulo.com.br)
> Grupo de Usuarios Java (www.guj.com.br)
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Marko Štrukelj 2002-11-20 09:19:18 Re: jdbc bug/feature?
Previous Message Barry Lind 2002-11-20 08:15:55 Re: calling isClosed appears to hang