Re: Blobs

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Blobs
Date: 2008-03-14 12:20:41
Message-ID: frdqip$j67$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Marc Horvath, 14.03.2008 12:35:
> I was wondering if anyone had any working sample code of inserting a
> blob into a table and then retrieving one from a table for viewing?
>
> I’m using Postgres 8.2, the jdbc is postgresql-8.2-504.jdbc3, and the
> Java is 1.6.
>
> I’m also running on a Windows XP Pro box if that matters.

You should probably have posted that to the JDBC mailing list.

I am using the following code successfully:

PreparedStatement stmt = connection.prepareStatement("insert into blob_table (id, blob_data) values (?,?)";

File f = new File("pretty_image.jpg");
FileInputStream f = new FileInputStream(f);
stmt.setInt(1, 42),
stmt.setBinaryStream(2, f, (int)f.length());
stmt.executeUpdate();

connection.commit();

Note that the field blob_table is defined as bytea in Postgres

Regards
Thomas

In response to

  • Blobs at 2008-03-14 11:35:15 from Marc Horvath

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2008-03-14 12:22:34 Re: postgre vs MySQL
Previous Message Marko Kreen 2008-03-14 12:17:54 Re: Trigger to run @ connection time?