Обсуждение: updateBlob()-example?

Поиск
Список
Период
Сортировка

updateBlob()-example?

От
Guido Fiala
Дата:
Hallo together,

maybe someone can help - i can get updateBlob() working and i couldn't find
any working example so far.

ResultSet rs...
Blob b=getBlob(1);

works just fine, but how do i store a modified value in the database?

I tried:

bytes[] bt=...;//something binary

Blob newblob=new Blob(); //does not work, Blob is not instanciateable

//writing the "Blobs" data as byte[]-Array using

rs.updateBytes(1, bt);

//fails because it modifies the contents of the byte[], or maybe i don't
//understand what this function can be used for.

Blob b=rs.getBlob(1);

// throws null-pointer for insertRow and "wrong format for integer" for
// updateRow, although row "1" is definitely an varchar-column

b.setBytes(0,bt); //could not test because of above
rs.updateBlob(b);// dito

What is the right (and efficient) way to do this?

Guido

remark: as the large-object table is named to be a "potential security leak"
as all user have the right to read from it, i like to store values for
(middle sized) objects directly in my tables.


Re: updateBlob()-example?

От
Kris Jurka
Дата:

On Thu, 12 Feb 2004, Guido Fiala wrote:

> Hallo together,
>
> maybe someone can help - i can get updateBlob() working and i couldn't find
> any working example so far.
>

It is entirely unclear what your column's underlying data type is, for
binary data it should be oid or bytea, but the only mention of datatype in
your email is varchar.  The Blob interface only works with the oid
datatype and large object method and even then support is poor.  JDBC3 has
added write support for blobs, but these have not been implemented in the
pg JDBC driver.  If you want to use large objects the easiest way is to
pass compatible=7.1 as a URL parameter and then use setBytes/getBytes.
Could you be more clear on what you want to do and where it is failing?
The numerous one line snippets you have included aren't clear and actually
seem contradictory to me.

Kris Jurka


Re: updateBlob()-example?

От
Guido Fiala
Дата:
Am Donnerstag, 12. Februar 2004 10:05 schrieb Kris Jurka:
> It is entirely unclear what your column's underlying data type is, for
> binary data it should be oid or bytea, but the only mention of datatype in
> your email is varchar.  The Blob interface only works with the oid

That was failure number one ;-)

> datatype and large object method and even then support is poor.  JDBC3 has
> added write support for blobs, but these have not been implemented in the
> pg JDBC driver.  If you want to use large objects the easiest way is to

Ok, then i would use setBytes/getBytes anyway.

> pass compatible=7.1 as a URL parameter

How do i specify that paramter in the URL?

>and then use setBytes/getBytes.

> Could you be more clear on what you want to do and where it is failing?

I tried using rs.updateBytes() and using bytea datatype and writing seems to
work now.
But if the data are read back using getBytes() the RTF-Editorkit mourns about
"to many closed brackets", but that might not be a problem of JDBC, still
tracking it down.

Have not yet tried using setBytes() - would that make a difference other than
speed?

> The numerous one line snippets you have included aren't clear and actually
> seem contradictory to me.

Sorry - yes they were contradictory, i just pointed out all ways i tried
already.

Thanks,
    Guido

Re: updateBlob()-example?

От
Kris Jurka
Дата:

On Thu, 12 Feb 2004, Guido Fiala wrote:

> Am Donnerstag, 12. Februar 2004 10:05 schrieb Kris Jurka:
> > pass compatible=7.1 as a URL parameter
>
> How do i specify that paramter in the URL?
>

Something like:

jdbc:postgresql://localhost:5432/mydatabase?compatible=7.1


> > Could you be more clear on what you want to do and where it is failing?
>
> I tried using rs.updateBytes() and using bytea datatype and writing seems to
> work now.
> But if the data are read back using getBytes() the RTF-Editorkit mourns about
> "to many closed brackets", but that might not be a problem of JDBC, still
> tracking it down.
>

There is a bug in the server where it tries to do character set conversion
on bytea data.  If your database is not in UNICODE encoding this may be
the issue.  Using unicode or large objects will avoid this problem.

Kris Jurka