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

JDBC + large objects problem

From: Patrick Goodwill <goodwill(at)cheese(dot)stanford(dot)edu>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: JDBC + large objects problem
Date: 2000-08-25 21:25:27
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
I'm trying to use JDBC and BLOBS to store large amounts of text in a
database.  I get a strange error when I try to use the conventional JDBC
interface... it comes out with a SQL Exceptions of:

"InputStream as parameter not supported"

for the code:

	    Connection conn = pool.getConnection();	    
	    PreparedStatement pstmt = 
		conn.prepareStatement("INSERT INTO t" + book 
				      + "_data (author_id, title, text,
                                      type) VALUES ( ?, ?, ?, ?)");
	    pstmt.setInt(1, userId);
	    pstmt.setString(2, title);
	    InputStream textStream = stringToStream(text);
	    pstmt.setBinaryStream(3, textStream, text.length());
	    pstmt.setInt(4, type);

... with some helper functions....

    private InputStream stringToStream(String string) {
	byte[] bytes = string.getBytes();
	ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
	return (InputStream) stream;

    private String      streamToString(InputStream stream) {
	try {
	    int length = stream.available();
	    byte[] bytes = new byte[length];;
	    return new String(bytes);
	} catch (IOException e) {
	    System.out.println("No Stream");
	return null;

with an abbreviated schema of....

>> \d t1_data
                               Table "t1_data"
 Attribute |  Type   |                       Modifier
 data_id   | integer | not null default
 author_id | integer |
 title     | text    |
 text      | oid     |
 type      | integer |
 time      | time    |
Index: t1_data_pkey   

.... using postgresql 7.0 and the newest JDBC driver from

if ya'll have any ideas why it does what it does, i just might kiss your
feet.  =)



pgsql-interfaces by date

Next:From: Rob JuddDate: 2000-08-25 22:16:10
Subject: Re: JDBC + large objects problem
Previous:From: Manika deyDate: 2000-08-25 21:19:00
Subject: RE: using large objects with jdbc

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