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.



Thanks,

Marc

Search Discussions

  • Thomas Kellerer at Mar 14, 2008 at 12:20 pm

    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-general @
categoriespostgresql
postedMar 14, '08 at 11:35a
activeMar 14, '08 at 12:20p
posts2
users2
websitepostgresql.org
irc#postgresql

2 users in discussion

Marc Horvath: 1 post Thomas Kellerer: 1 post

People

Translate

site design / logo © 2021 Grokbase