From: | Wieger Uffink <wieger(at)usmedia(dot)nl> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Storing/retreiving Large Objects |
Date: | 2002-01-09 15:18:21 |
Message-ID: | 1010589501.1414.5.camel@barcelona.usmedia.nep |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-jdbc |
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(at)usmedia(dot)nl
--
From | Date | Subject | |
---|---|---|---|
Next Message | Mike Mascari | 2002-01-09 16:03:22 | Any way to automatically promote NOTICEs to ERRORs? |
Previous Message | BELLON Michel | 2002-01-09 15:16:41 | Unable to start |
From | Date | Subject | |
---|---|---|---|
Next Message | Dave Cramer | 2002-01-09 15:39:19 | Re: behavior of getTables() wrt capitalization of type |
Previous Message | brian zimmer | 2002-01-09 15:12:10 | Re: behavior of getTables() wrt capitalization of type |