Received: from waco2.calpha.com (waco2.calpha.com [208.232.233.3]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id eB3JAhF23171 for ; Sun, 3 Dec 2000 14:10:43 -0500 (EST) (envelope-from Greg@10happythings.com) Received: from 10happythings.com (gspeegle.t1-s.wireless.calpha.com [63.80.26.25] (may be forged)) by waco2.calpha.com (8.10.1/8.10.1) with ESMTP id eB3JAM717812; Sun, 3 Dec 2000 13:10:23 -0600 Message-ID: <3A2A9A9D.9000803@10happythings.com> Date: Sun, 03 Dec 2000 13:10:21 -0600 From: Greg Speegle User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0 X-Accept-Language: en MIME-Version: 1.0 To: Ingo Luetkebohle CC: pgsql-interfaces@postgresql.org Subject: Re: jdbc: getBinaryStream blocks on second call References: <20001203171302.B1619@blank.pages.de> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Archive-Number: 200012/17 X-Sequence-Number: 354 Within JDBC 1.0, it is required to access the columns in a result set row from left to right and only once. Since the Postgres JDBC driver is not totally 2.0, it's not mandatory, but it is a real good idea. I'd suggest storing the byte array somewhere so you don't have to read it twice. If you have to read it twice, the only way to gaurantee that it works, is to close the Statement and do it again. Greg Speegle Baylor University Ingo Luetkebohle wrote: > Hello, > > I'm using the Postgresql-JDBC interface inside of a Jave Server Page > and request a large object. When the page is first called, it works > fine. When its called twice for the same database row, the > ResultSet.getBinaryStream method blocks infinetely. This is on > postgresql 7.0.3 (from RPM, on Linux, glibc). > > The code is something like: > > dbc.setAutoCommit(false); > Statement st = dbc.createStatement(); > ResultSet rs = st.executeQuery("SELECT contents FROM file WHERE id=" + id); > dbc.commit(); > if(rs.next()) { > Reader r = new InputStreamReader(rs.getBinaryStream(1)); > char buf[] = new char[2048]; > for(int read = r.read(buf); read != -1; read = r.read(buf)) > out.write(buf, 0, read); > > out.flush(); > r.close(); > is.close(); > } > > (yes, I known that the getBytes method is more convenient but the > JspWriter class a JSP page provides can't write byte[], only char[]) >