From: | Gunther Schadow <gunther(at)aurora(dot)rg(dot)iupui(dot)edu> |
---|---|
To: | Marcin Mazurek - Multinet SA - Poznan <m(dot)mazurek(at)multinet(dot)pl> |
Cc: | pgsql-general(at)postgreSQL(dot)org |
Subject: | Re: [GENERAL] Large objects + JDBC |
Date: | 1999-12-13 16:40:53 |
Message-ID: | 38552195.43DA2CD9@aurora.rg.iupui.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Marcin Mazurek - Multinet SA - Poznan wrote:
> Hi,
> I'm put several gifa into a table. I did as a exercise:) form psql using:
> INSERT INTO images (id, data)
> VALUES (3, lo_import('/usr/local/apache/servlets/images/a.gif'));
are you sure this lo_import(...) thing in the SQL will work? I have no
idea ...
> but I have a problem with creating Java stream to read these data. Here
> serveral lines of code I was using:
> PreparedStatement ps=db.prepareStatement("select oid from imag where id=?");
> ps.setInt(1,1);
> ResultSet rs = ps.executeQuery();
> rs.next();
> InputStream is = rs.getBinaryStream(0);
> and nothing happens:( Several messages from exceptions:
> [13/12/1999 18:11:04:815 CET] ShowImageServlet1: 0
> null
> Fastpath: ERROR: lo_tell: large object descriptor (-1) out of range
I see two problems with your above Java code snippet:
#1: you SELECT oid FROM imag ... only the OID? Would you not have to select
the data? A SELECT that would match your insert above would be:
SELECT data FROM images WHERE id=?;
#2: your index in rs.getBinaryStream is zero, but if I recall correctly
the JDBC ResultSet.getXXX(int) functions start counting at 1, not at
0. So, you should have called:
PreparedStatement ps=db.prepareStatement(
"SELECT data FROM image WHERE id=?"); // select data instead of oid
ps.setInt(1,1);
ResultSet rs = ps.executeQuery();
if(rs.next()) {
InputStream is = rs.getBinaryStream(1); // start with one (1)
}
I have never done this BLOB stuff, but you might try whether this
fixes the problem. Also, with the JDBC driver comes a test that
does exactly image storing and retrieval. So you can look there
for a working example.
regards
-Gunther
--
Gunther_Schadow-------------------------------http://aurora.rg.iupui.edu
Regenstrief Institute for Health Care
1050 Wishard Blvd., Indianapolis IN 46202, Phone: (317) 630 7960
schadow(at)aurora(dot)rg(dot)iupui(dot)edu------------------#include <usual/disclaimer>
Attachment | Content-Type | Size |
---|---|---|
gunther.vcf | text/x-vcard | 340 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Ed Loehr | 1999-12-13 18:37:30 | [GENERAL/INTERFACES] Dynamically detecting need to vacuum? |
Previous Message | Manuel Lemos | 1999-12-13 16:28:21 | Can't I create indexes on BOOL columns? |