Re: Problem with LargeObject/jdbc when writing short (Repost) - Mailing list pgsql-jdbc

From Fernando Nasser
Subject Re: Problem with LargeObject/jdbc when writing short (Repost)
Date
Msg-id 3F267DFC.1080607@redhat.com
Whole thread Raw
In response to Problem with LargeObject/jdbc when writing short (Repost)  (Ole Streicher <ole-usenet-spam@gmx.net>)
List pgsql-jdbc
Hi,

I run your test program with the current driver and I get the whole lot:

(...)
1997
1998
1999
End of file reached.


Why don't you try the new driver?  It is backward compatible with your
7.2 backend.  It may have been a problem in the past that has been fixed
since...

Regards,
Fernando



Ole Streicher wrote:
> Hi group,
>
> since my last mail made it through, I assume that the previous one
> just magically diappeared. Here it is again:
>
> I have a problem when trying to use the getInputStream()/getOutputStream()
> methods of LargeObject. The problem is demonstrated by the code I append
> to this post.
>
> There I create a LargeObject and put there all numbers from 100 to
> 2000 as shorts. Afterwards, I re-open this object by its oid, read
> itout and print it on the screen.
>
> The funny thing is that the program stops after writing the 127 on the
> screen. So, either the writing was silently stopping with number 128,
> or the reader creates a EOFException when the 8th bit was set.
>
> The Postgresql version is 7.2.2, the jdbc driver is jdbc7.1-1.2.jar,
> both directly from the SuSE 8.1 CD.
>
> What is the cause of that and what can I do to get a correct behaviour?
> Is it a bug or did I just not carefully read the manual?
>
> Ciao
>
> Ole
>
> This is the Code:
> ---------------------------------8<------------------------------------------
> import java.io.*;
> import java.sql.*;
> import org.postgresql.largeobject.*;
>
> public class PgTest {
>   public static void main (String[] args) {
>     try {
>       Class.forName("org.postgresql.Driver");
>       Connection dbConn
>         = DriverManager.getConnection("jdbc:postgresql:ole", "ole", "nixda");
>       dbConn.setAutoCommit(false);
>       LargeObjectManager lobjm =
>         ((org.postgresql.Connection)dbConn).getLargeObjectAPI();
>
>       int oid = lobjm.create(LargeObjectManager.READ
>                              | LargeObjectManager.WRITE);
>       System.out.println("Oid is " + oid);
>
> // *** 1st Step: write 1900 shorts ***
>       LargeObject wobj = lobjm.open(oid, LargeObjectManager.WRITE);
>       DataOutputStream dos = new DataOutputStream(wobj.getOutputStream());
>       for (short i = 100; i < 2000; i++) {
>         dos.writeShort(i);
>       }
>       dos.close();
>       wobj.close();
>       dbConn.commit();
>
> // *** 2nd Step: read these shorts back from the same OID ***
>       LargeObject robj = lobjm.open(oid, LargeObjectManager.READ);
>       DataInputStream is = new DataInputStream(robj.getInputStream());
>       try {
>         while (true) {
>           System.out.println(is.readShort());
>         }
>       } catch (EOFException e) {
>         System.out.println("End of file reached.");
>       }
>       robj.close();
>     } catch (Exception e) {
>       e.printStackTrace();
>     }
>   }
> }
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>


--
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9


pgsql-jdbc by date:

Previous
From: Peter Royal
Date:
Subject: NPE in creating a SQLException
Next
From: "Scot P. Floess"
Date:
Subject: Re: NPE in creating a SQLException