Fwd: Large Objects (please help) - Mailing list pgsql-jdbc

From Peter T Mount
Subject Fwd: Large Objects (please help)
Date
Msg-id 5.1.0.14.0.20011008150257.02651bf8@mail.retep.org.uk
Whole thread Raw
Responses Re: Fwd: Large Objects (please help)  (Dave Harkness <daveh@MEconomy.com>)
List pgsql-jdbc
I'm forwarding this to the jdbc list.

Peter

>Hi Peter,
>
>I am trying to insert and/or select from Postgres a gif image by using
>the Large Object type.   I am writing a Java client and middle tier to a
>Postgres db backend using your JDBC driver and I have hit an issue with
>what your documantation shows and the exceptions I am seeing when I run
>a simple comand line program.
>
>here is the java code I am running:
>
>....
>   File file = new File("...(some path).../tomcat.gif");
>   FileInputStream fis = new FileInputStream(file);
>   PreparedStatement ps = db.prepareStatement("insert into image values
>(?,?)");
>   ps.setString(1,file.getName());
>   //ps.setObject(2,fis,java.sql.Types.LONGVARBINARY);
>   ps.setBinaryStream(2,fis, file.length());
>   ps.executeUpdate();
>   ps.close();
>   fis.close();
>....
>
>The code is almost verbatim from your documentation.
>"image" is a table  containing a image name and oid attributes.  I have
>tried both the statements,  ps.setBinaryStream(2,fis, file.length())
>and  ps.setObject(2,fis,java.sql.Types.LONGVARBINARY).  The first
>statement produces a compile time error :
>
>main.java:70: setBinaryStream(int,java.io.InputStream,int) in
>java.sql.PreparedStatement cannot be applied to
>(int,java.io.FileInputStream,long)
>   ps.setBinaryStream(2,fis, file.length());
>
>The JDBC API confuses me a little.  Why doesn't the JDBC interface
>define a long for this argument?  After all, we are dealing with big
>byte streams.  Hmm.
>
>The second statement, ps.setObject(2,fis,java.sql.Types.LONGVARBINARY),
>which I thought would be a good substitute produces a runtime exception:
>
>Unknown Types value.
>  at
>org.postgresql.jdbc2.PreparedStatement.setObject(PreparedStatement.java:492)
>
>  at
>org.postgresql.jdbc2.PreparedStatement.setObject(PreparedStatement.java:498)
>
>  at main.main(main.java:69)
>
>Does your driver fully implement the JDBC API?  LONGVARBINARY  is a
>valiid java.sql data type.  Maybe I have an old version of your driver.
>
>Here is my environment:
>PostgreSQL 7.0.3 on i686-pc-linux-gnu, compiled by gcc 2.96
>jdbc7.0-1.2.jar
>java full version "1.4.0-beta2-b77"
>uname -a
>Linux localhost.localdomain 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686
>unknown
>
>Any help would be appreciated.  Thank you.
>
>Cheers,
>Brian Buck



pgsql-jdbc by date:

Previous
From: Barry Lind
Date:
Subject: Re: flames!
Next
From: Dave Harkness
Date:
Subject: Re: Fwd: Large Objects (please help)