From: | Kris Jurka <books(at)ejurka(dot)com> |
---|---|
To: | Frederic Thomas <frederic(at)instranet(dot)com> |
Cc: | <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | Re: java.lang.NegativeArraySizeException at |
Date: | 2003-11-18 07:50:12 |
Message-ID: | Pine.LNX.4.33.0311180225570.21643-200000@leary.csoft.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
On Tue, 18 Nov 2003, Frederic Thomas wrote:
> Hello,
>
> I've the following code :
>
> ...
> ByteArrayInputStream is = new
> ByteArrayInputStream(str.getBytes());
> prepStatement.setBinaryStream(1, is, str.getBytes().length); // can
> be UTF-8
> ...
>
> assuming that prepStatement is a correct query that updates a row containing
> a TEXT field, in column 1, and str represents a Unicode string to store in
> this TEXT field. When running this exact code with PostgreSQL 7.2 driver
> using the "?compatible=7.1" switch, it was working just fine when called
> with an empty str (str = ""). When I ported this application to use
> PostgreSQL 7.3 driver without the "?compatible=7.1", this code produces a
> java.lang.NegativeArraySizeException on the prepStatement.setBinaryStream()
> line.
>
> FYI, I noted that I had to change OID to BYTEA in my schema for the BLOBs in
> order to upgrade from 7.1 to 7.3 compatibility mode, but didn't see anything
> regarding TEXT fields (CLOB). I can also add that I tried all the different
> 7.3 drivers as well as the latest 7.4 dev driver with the exact same error.
> Finally, I couldn't find, in the Java 1.3 documentation, anything regarding
> the second and third parameters of PreparedStatement.setBinaryStream()
> which, to me, can be null and 0 respectively.
>
I think the real question is: why are you calling setBinaryStream on a
text field? Shouldn't you just do: prepStatement.setString(1,str);
instead of going through the BinaryStream?
In any case the driver shouldn't throw an Exception like that. Here's a
patch that fixes that.
Kris Jurka
Attachment | Content-Type | Size |
---|---|---|
pstmt.setBinaryStream.patch | text/plain | 882 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Frederic Thomas | 2003-11-18 08:45:44 | Re: java.lang.NegativeArraySizeException at org.postgresql.jdbc1.AbstractJdbc1Statement.setBinaryStream() |
Previous Message | Frederic Thomas | 2003-11-18 07:19:38 | java.lang.NegativeArraySizeException at org.postgresql.jdbc1.AbstractJdbc1Statement.setBinaryStream() |