Storing/retreiving Large Objects - Mailing list pgsql-general

From Wieger Uffink
Subject Storing/retreiving Large Objects
Date
Msg-id 1010589501.1414.5.camel@barcelona.usmedia.nep
Whole thread Raw
List pgsql-general
Hi,

Im trying to store images in my postgres db through jdbc access. The
connections are pooled through poolman. So far I have only tried to get
the manual's example in section 8.5 to work. Ive included the example
below.

I have literally c&p the example and the inserting the image seems to go
well since it results in populated row in table 'images'.
WHen I try to retreive the the image either through ps.getBinaryStream()
or ps.getBlob() I get a Class cast exception thrown at me, nl:

java.lang.ClassCastException: java.lang.Integer
    at
com.codestudio.sql.PoolManResultSet.getBlob(PoolManResultSet.java:414)

Apparently the oid stored in the table is retreived as an integer, which
obviously cannot be cast into a BinaryStream.
ANyone have any idea what could be going wrong here? Maybe some poolman
type mapping configuration or something.

Thanks in advance,
Wieger



//Example 8-2. Using the JDBC Large Object Interface

//For example, suppose you have a table containing the file name of an
//image and you have a large object containing that image:

//CREATE TABLE images (imgname text, imgoid oid);

//To insert an image, you would use:

File file = new File("myimage.gif");
FileInputStream fis = new FileInputStream(file);
PreparedStatement ps = conn.prepareStatement("INSERT INTO images VALUES
(?, ?)"); (1)
ps.setString(1, file.getName());
ps.setBinaryStream(2, fis, file.length());
ps.executeUpdate();
ps.close();
fis.close();

//retreiving
PreparedStatement ps = con.prepareStatement("SELECT oid FROM images
WHERE name=?");
ps.setString(1, "myimage.gif");
ResultSet rs = ps.executeQuery();
if (rs != null) {
    while(rs.next()) {
        InputStream is = rs.getBinaryInputStream(1);
        // use the stream in some way here
        is.close();
    }
    rs.close();
}
ps.close();


--

Wieger Uffink
tel: +31 20 468 6868
fax: +31 20 470 6905
web: http://www.usmedia.nl
email: wieger@usmedia.nl

--


pgsql-general by date:

Previous
From: BELLON Michel
Date:
Subject: Unable to start
Next
From: Mike Mascari
Date:
Subject: Any way to automatically promote NOTICEs to ERRORs?