getBlob problems with bytea type columns

From: Dave Weis <djweis(at)sjdjweis(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: getBlob problems with bytea type columns
Date: 2001-09-08 22:38:03
Message-ID: Pine.LNX.4.21.0109081731040.10041-100000@oliver.internal.sjdjweis.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)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(at)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(at)sjdjweis(dot)com of the freedom of the people by gradual and silent
encroachments of those in power than by violent
and sudden usurpations."- James Madison

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Bruce Momjian 2001-09-09 01:10:12 Re: Fix JDBC test suite, set/get transaction isolation level
Previous Message Rene Pijlman 2001-09-08 22:18:05 Re: [HACKERS] JDBC pg_description update needed for CVS tip