Search Postgresql Archives

Re: Blobs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux