From: | Barry Lind <barry(at)xythos(dot)com> |
---|---|
To: | Wieger Uffink <wieger(at)usmedia(dot)nl> |
Cc: | pgsql-jdbc(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Storing/retreiving Large Objects |
Date: | 2002-01-09 18:11:53 |
Message-ID: | 3C3C87E9.7020306@xythos.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-jdbc |
FYI. This should have gone to the pgsql-jdbc mail list instead of
pgsql-general.
What version are you using? This area of the code has undergone some
significant work in 7.2. I would suggest you try using the 7.2 jdbc
code (which will run fine against a 7.1 database). Also look at the 7.2
documentation as it also has been updated significantly in this area.
I cannot reproduce your problem using the 7.2 drivers given the test
case below.
thanks,
--Barry
Wieger Uffink wrote:
> 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();
>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2002-01-09 19:25:09 | Re: PSQL core dumps |
Previous Message | Peter E. Chen | 2002-01-09 18:11:13 | Question regarding VACUUM ANALYZE ERROR . . . |
From | Date | Subject | |
---|---|---|---|
Next Message | Benjamin.Feinstein | 2002-01-09 18:49:44 | LISTEN/NOTIFY support? |
Previous Message | Lloyd Holman | 2002-01-09 16:32:58 | postgresql JDBC error |