pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Bug with blobs?
3+ messages / 2 participants
[nested] [flat]

* Bug with blobs?
@ 2005-08-11 18:09  Rob Kirkbride <rob@rkcomputing.co.uk>
  0 siblings, 1 reply; 3+ messages in thread

From: Rob Kirkbride @ 2005-08-11 18:09 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

I was getting an exception thrown when using Hibernate to read blobs but
I've pared it down to something very simple - hopefully it's just
something silly.
Here's the snippet of code :-


            String query = "select imageblob from tempimages where id=1";

                Connection con;
                PreparedStatement s;
                ResultSet rs;

                try {
                    Class.forName(driver);
                    con = DriverManager.getConnection(url, username,
password);
                    s = con.prepareStatement(query);
                    rs = s.executeQuery();
                    rs.next();
                    java.sql.Blob blob = rs.getBlob("imageblob");

It throws a
org.postgresql.util.PSQLException: Bad value for type int :
\377\330\377\340\000 .... <blob data removed>
    at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.toInt(AbstractJdbc2ResultSet.java:2528)
    at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2003)
    at org.postgresql.jdbc3.Jdbc3ResultSet.getBlob(Jdbc3ResultSet.java:55)
    at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getBlob(AbstractJdbc2ResultSet.java:323)
    at PgTest.run(PgTest.java:46)
    at PgTest.main(PgTest.java:63)

This is with postgresql 8.0.3 and version 312 of the driver (on Linux)

Help, help! - What am I doing wrong!?

Thanks for any help,

Rob







^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Bug with blobs?
@ 2005-08-11 18:36  Kris Jurka <books@ejurka.com>
  parent: Rob Kirkbride <rob@rkcomputing.co.uk>
  0 siblings, 1 reply; 3+ messages in thread

From: Kris Jurka @ 2005-08-11 18:36 UTC (permalink / raw)
  To: Rob Kirkbride <rob@rkcomputing.co.uk>; +Cc: pgsql-jdbc



On Thu, 11 Aug 2005, Rob Kirkbride wrote:

> I was getting an exception thrown when using Hibernate to read blobs but
> I've pared it down to something very simple - hopefully it's just
> something silly.
>
>           String query = "select imageblob from tempimages where id=1";
>
>                   java.sql.Blob blob = rs.getBlob("imageblob");
>
> It throws a
> org.postgresql.util.PSQLException: Bad value for type int :
> \377\330\377\340\000 .... <blob data removed>
>   at
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.toInt(AbstractJdbc2ResultSet.java:2528)
>   at

Postgresql maps Blob data to the oid datatype, not bytea.  For bytea data 
you should use getBytes() not getBlob.

Kris Jurka



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Bug with blobs?
@ 2005-08-11 19:55  Rob Kirkbride <rob@rkcomputing.co.uk>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Rob Kirkbride @ 2005-08-11 19:55 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

Kris Jurka wrote:

>
>
> On Thu, 11 Aug 2005, Rob Kirkbride wrote:
>
>> I was getting an exception thrown when using Hibernate to read blobs but
>> I've pared it down to something very simple - hopefully it's just
>> something silly.
>>
>>           String query = "select imageblob from tempimages where id=1";
>>
>>                   java.sql.Blob blob = rs.getBlob("imageblob");
>>
>> It throws a
>> org.postgresql.util.PSQLException: Bad value for type int :
>> \377\330\377\340\000 .... <blob data removed>
>>   at
>> org.postgresql.jdbc2.AbstractJdbc2ResultSet.toInt(AbstractJdbc2ResultSet.java:2528) 
>>
>>   at
>
>
> Postgresql maps Blob data to the oid datatype, not bytea.  For bytea 
> data you should use getBytes() not getBlob.
>
> Kris Jurka
>
Thanks. It's actually being done within Hibernate so I don't have a
great deal of control but I'll try using the binary type which works
with bytea and hopefully will be ok.

Rob





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-08-11 19:55 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-08-11 18:09 Bug with blobs? Rob Kirkbride <rob@rkcomputing.co.uk>
2005-08-11 18:36 ` Kris Jurka <books@ejurka.com>
2005-08-11 19:55   ` Rob Kirkbride <rob@rkcomputing.co.uk>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox