1

I am using postgresql 9.2 and ,when I read the data from Bytea(used to store binary large object data in postgresql) field using getBlob() method but I'm getting the same error

Error: type bad value for long. 

I know that I'm getting this error because of only getBinaryStream() and getBytes() method works with this(Bytea) and getBlob() method works with OID type field. But I have situation.So I would like to know that, is there any way to read the data from Bytea using getBlob() method in Postgresql9.2 . Thank you in advance.

Krishna
  • 795
  • 2
  • 7
  • 24
  • Show your code and the table definition please - edit the question to add the appropriate info (and read the formatting info while you're at it). – Craig Ringer Apr 25 '14 at 05:51
  • @Craig Ringer Table definition is: create table test(data bytea); and if i'm using setBinaryStream() method to writing serialized object data into data field. when I am using getBinaryStream() or getBytes() method to read data from data field then it's ok but i want to read data using getBlob() method... – Krishna Apr 25 '14 at 06:08
  • In future please *edit the question* to add things like table definitions, way easier to read. Anyway - I strongly suspect `getBlob()` expects you to have a `lo`, which is really an oid pointing to `pg_largeobject`. Take a look at the PgJDBC sources. – Craig Ringer Apr 25 '14 at 06:29
  • @Craig Ringer thank you..I got my answer – Krishna Apr 25 '14 at 07:09
  • For Postgresql9.2 which one is the best(for performance,memory,speed of accessing) method to read data from bytea field, getBinaryStream() or getBytes() for same scenario? – Krishna Apr 25 '14 at 07:12
  • Test and see. Personally expect `getBytes()` because PgJDBC doesn't currently support streaming `bytea` so it always reads the whole thing into memory anyway. – Craig Ringer Apr 25 '14 at 08:10
  • @Craig Ringer thank you so much to you, i got my answer and now i am going to use getBytes() – Krishna Apr 25 '14 at 09:46

0 Answers0