getBlob problems with bytea type columns

Поиск
Список
Период
Сортировка
Искать

getBlob problems with bytea type columns

От:
Dave Weis <djweis@sjdjweis.com>
Дата:

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

Re: getBlob problems with bytea type columns

От:
Rene Pijlman <rene@lab.applinet.nl>
Дата:
On Sat, 8 Sep 2001 17:38:03 -0500 (CDT), you wrote:
>I have been trying to figure out how the blob support works. 

See the explanation on http://lab.applinet.nl/postgresql-jdbc/
("Large objects (Blob and Clob)").

>I made a table of this format:
[...]
> theblob   | bytea   | 

Unfortunately, bytea is currently unsupported in the JDBC
driver.

Alternatively, you can use PostgreSQL large objects. See the
same link for pointers.

Regards,
René Pijlman 
FAQ