getBlob problems with bytea type columns - Mailing list pgsql-jdbc

From Dave Weis
Subject getBlob problems with bytea type columns
Date
Msg-id Pine.LNX.4.21.0109081731040.10041-100000@oliver.internal.sjdjweis.com
Whole thread Raw
Responses Re: getBlob problems with bytea type columns  (Rene Pijlman <rene@lab.applinet.nl>)
List pgsql-jdbc
I'm running Postgresql 7.1.2 on a RedHat 7.1 machine. I have the jdbc
drivers jdbc7.1-1.2.jar.

I have been trying to figure out how the blob support works. I made a
table of this format:

djweis=# \d blobtest
 id        | integer |
 theblob   | bytea   |

This is the code that I'm using to grab the value of 'theblob':

        conn.setAutoCommit(false);

        PreparedStatement stmt = conn.prepareStatement("SELECT theblob
FROM blobtest WHERE id = ?");
        stmt.setInt(1, 1);
        ResultSet rset = stmt.executeQuery();

        while (rset.next()) {

        Blob foo = rset.getBlob("theblob");

        System.out.println("length is " + foo.length());

        }

But instead of getting just the length, I get this:

[djweis@djweis pgblob]$ java -cp jdbc7.1-1.2.jar:. test
hello, world
Bad Integer I wish this would work
    at org.postgresql.jdbc2.ResultSet.getInt(ResultSet.java:269)
    at org.postgresql.jdbc2.ResultSet.getBlob(ResultSet.java:964)
    at org.postgresql.jdbc2.ResultSet.getBlob(ResultSet.java:959)
    at test.main(test.java:30)
Bad Integer I wish this would work
[djweis@djweis pgblob]$

I never printed the contents of the blob, but there they are... I inserted
the data by hand, but once I figure out how to do this, I'll need to
insert the data from InputStreams and get it back using OutputStreams.

Any ideas?

Thanks
dave


--
Dave Weis             "I believe there are more instances of the abridgement
djweis@sjdjweis.com   of the freedom of the people by gradual and silent
                      encroachments of those in power than by violent
                      and sudden usurpations."- James Madison


pgsql-jdbc by date:

Previous
From: Rene Pijlman
Date:
Subject: Re: [HACKERS] JDBC pg_description update needed for CVS tip
Next
From: Bruce Momjian
Date:
Subject: Re: Fix JDBC test suite, set/get transaction isolation level