Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-jdbc by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group