pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Mount <peter@retep.org.uk>
To: Patrick Goodwill <goodwill@cheese.stanford.edu>
To: pgsql-interfaces@postgresql.org
Subject: Re: JDBC + large objects problem
Date: Sat, 26 Aug 2000 10:56:16 +0100
Message-ID: <00a401c00f46$aa31ed60$2516989e@heather> (raw)
References: <Pine.BSF.4.21.0008251424240.1475-100000@cheese.stanford.edu>

Streams are not supported yet, hence the message.

There are various ways around this, all of which are discussed recently in
the list archives.

Peter

--
Peter T Mount  peter@retep.org.uk, me@petermount.com
Homepage: http://www.retep.org.uk Contact details: http://petermount.com
PostgreSQL JDBC: http://www.retep.org.uk/postgres/
Java PDF Generator: http://www.retep.org.uk/pdf/
----- Original Message -----
From: "Patrick Goodwill" <goodwill@cheese.stanford.edu>
To: <pgsql-interfaces@postgresql.org>
Sent: Friday, August 25, 2000 10:25 PM
Subject: [INTERFACES] JDBC + large objects problem


> 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);
>     pstmt.executeUpdate();
>     pstmt.close();
>
>
> ... 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];
>     stream.read(bytes);
>     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
>                                nextval('t1_data_data_id_seq'::text)
>  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 retep.org.uk
>
>
> if ya'll have any ideas why it does what it does, i just might kiss your
> feet.  =)
>
> -Patrick.
>
>




view thread (4+ messages)

Message-ID: <00a401c00f46$aa31ed60$2516989e@heather>
Permalink:  ../00a401c00f46$aa31ed60$2516989e@heather/
Also on:    postgresql.org/message-id/00a401c00f46$aa31ed60$2516989e@heather

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: peter@retep.org.uk, goodwill@cheese.stanford.edu
  Subject: Re: JDBC + large objects problem
  In-Reply-To: <00a401c00f46$aa31ed60$2516989e@heather>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox