Thread: Serialize its create method throws NullPointerException

Serialize its create method throws NullPointerException

From
"Daems, Huub"
Date:
Hi,

does some one has a clou how to use org.postgresql.util.Serialize to create
a table from my class....


package kermitserver.PL;

import java.io.*;
import java.util.*;
import java.sql.*;
import org.postgresql.util.Serialize;


public class Jk implements Serializable {

    public int oid;

    public Jk() {
    }

    public static void main(String[] args) {
        Jk jk1 = new Jk();
        jk1.oid = 0;   // just in case, only for this test

    try {
        Class.forName("org.postgresql.Driver");
        Connection db =
DriverManager.getConnection("jdbc:postgresql:kermitserver", "huub",
"secret");


org.postgresql.util.Serialize.create((org.postgresql.Connection)db, jk1);

        db.close();

    } catch (ClassNotFoundException cnfe) {
        cnfe.printStackTrace();
    } catch (SQLException sq) {
        sq.printStackTrace();
    } catch (NullPointerException npe) {
        npe.printStatckTrace();
    }
}


Try to run it and it gave an NullPointerException:

    java.lang.NullPointerException
    at org.postgresql.jdbc2.ResultSet.getString(ResultSet.java:171))
    at org.postgresql.util.Serialize.create(Serialize.java:241)
    at org.postgresql.util.Serialize.create(Serialize.java:220)
    at kermitserver.PL.jk.main(jk.java:37)

I am wondering what the ResultSet is doing.
I am using jdk1.3.1_01 from Sun, jdbc7.1-1.2.jar on postgresql 7.1.3 on SuSe
7.3

Would be nice if someone has an idea....

greeting Huub






Re: Serialize its create method throws NullPointerException

From
"Dave Cramer"
Date:
Huub,

The following code works

package postgrestest;

/**
 * Title:        Postgres Tests
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Ebox Inc
 * @author Dave Cramer
 * @version 1.0
 */

 /*
 *  Java sample program
 */

 import java.io.*;
 import java.sql.*;
 import org.postgresql.util.*;

 public class lili implements  Serializable
 {

  public String myString;
  public int myNumber;

  public lili()   throws ClassNotFoundException, FileNotFoundException,
IOException, SQLException
  {

    myString="theString";
    myNumber=4;
  }
  public boolean equals(lili l)
  {
    return (l.myString.equals(this.myString) && myNumber ==
this.myNumber);
  }
  private void testmethod(){};
  public void testmethod2x(){};

  public static void main(String args[])
  {
    org.postgresql.Connection conn=null;
    try {
      lili mylili = new lili();
      lili test = null;
      Class.forName("org.postgresql.Driver");         // load database
interface

// connect to the database
      conn =
(org.postgresql.Connection)DriverManager.getConnection("jdbc:postgresql:
//alpha.ebox.com/davec", "davec",   "");     // works
      // test of serialisation
      org.postgresql.util.Serialize.create(conn, mylili);     // makes
problems
      org.postgresql.util.Serialize s = new Serialize(conn,mylili);
      int oid  = s.store(mylili);
      test = (lili)s.fetch(oid);
      if (mylili.equals(test)){
        System.out.println("Success");
      }else{
        System.out.println("Failure");
      }
    } catch(Exception exc){
      System.err.println("Exception caught.\n" + exc);
      exc.printStackTrace();
    }finally{
      try {
        if (conn != null) conn.close();
      } catch (Exception ex){
      ;
      }
    }
  }

}

-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Daems, Huub
Sent: Tuesday, November 20, 2001 7:39 AM
To: 'pgsql-jdbc@postgresql.org'
Subject: [JDBC] Serialize its create method throws NullPointerException


Hi,

does some one has a clou how to use org.postgresql.util.Serialize to
create a table from my class....


package kermitserver.PL;

import java.io.*;
import java.util.*;
import java.sql.*;
import org.postgresql.util.Serialize;


public class Jk implements Serializable {

    public int oid;

    public Jk() {
    }

    public static void main(String[] args) {
        Jk jk1 = new Jk();
        jk1.oid = 0;   // just in case, only for this test

    try {
        Class.forName("org.postgresql.Driver");
        Connection db =
DriverManager.getConnection("jdbc:postgresql:kermitserver", "huub",
"secret");


org.postgresql.util.Serialize.create((org.postgresql.Connection)db,
jk1);

        db.close();

    } catch (ClassNotFoundException cnfe) {
        cnfe.printStackTrace();
    } catch (SQLException sq) {
        sq.printStackTrace();
    } catch (NullPointerException npe) {
        npe.printStatckTrace();
    }
}


Try to run it and it gave an NullPointerException:

    java.lang.NullPointerException
    at org.postgresql.jdbc2.ResultSet.getString(ResultSet.java:171))
    at org.postgresql.util.Serialize.create(Serialize.java:241)
    at org.postgresql.util.Serialize.create(Serialize.java:220)
    at kermitserver.PL.jk.main(jk.java:37)

I am wondering what the ResultSet is doing.
I am using jdk1.3.1_01 from Sun, jdbc7.1-1.2.jar on postgresql 7.1.3 on
SuSe 7.3

Would be nice if someone has an idea....

greeting Huub






---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly



Re: Serialize its create method throws NullPointerException

From
Barry Lind
Date:
There are many other frameworks out there for serializing java objects.
  The code in the postgres jdbc driver isn't very good, and will likely
be removed in the next release.  Depending on what you are trying to do,
I would start with the Java2 serialization code and store the result in
a bytea column.

thanks,
--Barry



Daems, Huub wrote:

> Hi,
>
> does some one has a clou how to use org.postgresql.util.Serialize to create
> a table from my class....
>
>
> package kermitserver.PL;
>
> import java.io.*;
> import java.util.*;
> import java.sql.*;
> import org.postgresql.util.Serialize;
>
>
> public class Jk implements Serializable {
>
>     public int oid;
>
>     public Jk() {
>     }
>
>     public static void main(String[] args) {
>         Jk jk1 = new Jk();
>         jk1.oid = 0;   // just in case, only for this test
>
>     try {
>         Class.forName("org.postgresql.Driver");
>         Connection db =
> DriverManager.getConnection("jdbc:postgresql:kermitserver", "huub",
> "secret");
>
>
> org.postgresql.util.Serialize.create((org.postgresql.Connection)db, jk1);
>
>         db.close();
>
>     } catch (ClassNotFoundException cnfe) {
>         cnfe.printStackTrace();
>     } catch (SQLException sq) {
>         sq.printStackTrace();
>     } catch (NullPointerException npe) {
>         npe.printStatckTrace();
>     }
> }
>
>
> Try to run it and it gave an NullPointerException:
>
>     java.lang.NullPointerException
>     at org.postgresql.jdbc2.ResultSet.getString(ResultSet.java:171))
>     at org.postgresql.util.Serialize.create(Serialize.java:241)
>     at org.postgresql.util.Serialize.create(Serialize.java:220)
>     at kermitserver.PL.jk.main(jk.java:37)
>
> I am wondering what the ResultSet is doing.
> I am using jdk1.3.1_01 from Sun, jdbc7.1-1.2.jar on postgresql 7.1.3 on SuSe
> 7.3
>
> Would be nice if someone has an idea....
>
> greeting Huub
>
>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
>



Re: Serialize its create method throws NullPointerException

From
"Daems, Huub"
Date:
I needed a way to persist my data which is kept in an object with several
"data-fields". Dave has pointed me to the right direction. I needed the
latest driver jdbc7.2dev-1.2.jar. The problem I had was solved by this new
driver.

Thanks for all the help.

Greetings Huub
PS
the code below works with the new driver. Thanks Dave


SELEKTVRACHT

  Postbus 40229           Atoomweg 30        Tel. 030-2477926
3504 AA  Utrecht        3542 AB  Utrecht        Fax
030-2477900

zakelijk mailto:Huub.Daems@selektvracht.nl
privé mailto:h.daems1@wanadoo.nl






> -----Original Message-----
> From:    Barry Lind [SMTP:barry@xythos.com]
> Sent:    dinsdag 20 november 2001 18:34
> To:    Daems, Huub; pgsql-jdbc@postgresql.org
> Subject:    Re: Serialize its create method throws NullPointerException
>
> There are many other frameworks out there for serializing java objects.
>   The code in the postgres jdbc driver isn't very good, and will likely
> be removed in the next release.  Depending on what you are trying to do,
> I would start with the Java2 serialization code and store the result in
> a bytea column.
>
> thanks,
> --Barry
>
>
>
> Daems, Huub wrote:
>
> > Hi,
> >
> > does some one has a clou how to use org.postgresql.util.Serialize to
> create
> > a table from my class....
> >
> >
> > package kermitserver.PL;
> >
> > import java.io.*;
> > import java.util.*;
> > import java.sql.*;
> > import org.postgresql.util.Serialize;
> >
> >
> > public class Jk implements Serializable {
> >
> >     public int oid;
> >
> >     public Jk() {
> >     }
> >
> >     public static void main(String[] args) {
> >         Jk jk1 = new Jk();
> >         jk1.oid = 0;   // just in case, only for this test
> >
> >     try {
> >         Class.forName("org.postgresql.Driver");
> >         Connection db =
> > DriverManager.getConnection("jdbc:postgresql:kermitserver", "huub",
> > "secret");
> >
> >
> > org.postgresql.util.Serialize.create((org.postgresql.Connection)db,
> jk1);
> >
> >         db.close();
> >
> >     } catch (ClassNotFoundException cnfe) {
> >         cnfe.printStackTrace();
> >     } catch (SQLException sq) {
> >         sq.printStackTrace();
> >     } catch (NullPointerException npe) {
> >         npe.printStatckTrace();
> >     }
> > }
> >
> >
> > Try to run it and it gave an NullPointerException:
> >
> >     java.lang.NullPointerException
> >     at org.postgresql.jdbc2.ResultSet.getString(ResultSet.java:171))
> >     at org.postgresql.util.Serialize.create(Serialize.java:241)
> >     at org.postgresql.util.Serialize.create(Serialize.java:220)
> >     at kermitserver.PL.jk.main(jk.java:37)
> >
> > I am wondering what the ResultSet is doing.
> > I am using jdk1.3.1_01 from Sun, jdbc7.1-1.2.jar on postgresql 7.1.3 on
> SuSe
> > 7.3
> >
> > Would be nice if someone has an idea....
> >
> > greeting Huub
> >
> >
> >
> >
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 3: if posting/reading through Usenet, please send an appropriate
> > subscribe-nomail command to majordomo@postgresql.org so that your
> > message can get through to the mailing list cleanly
> >
> >
>

Re: Serialize its create method throws NullPointerException

From
"Dave Cramer"
Date:
Huub,

There is a proposal on the list to remove the serialization code. It is
quite likely that it will be removed in the next release. As an
alternative, here is a list of persistence layers that work much better

http://www.ambysoft.com/persistenceLayer.html#ProductsFromPaper

FWIW the one I use is Artem Rudoy's implementation. This can be found at
www.sourceforge.net/player

Dave

-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Daems, Huub
Sent: Tuesday, November 20, 2001 1:19 PM
To: 'Barry Lind'; Daems, Huub; pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] Serialize its create method throws
NullPointerException


I needed a way to persist my data which is kept in an object with
several "data-fields". Dave has pointed me to the right direction. I
needed the latest driver jdbc7.2dev-1.2.jar. The problem I had was
solved by this new driver.

Thanks for all the help.

Greetings Huub
PS
the code below works with the new driver. Thanks Dave


SELEKTVRACHT

  Postbus 40229           Atoomweg 30        Tel. 030-2477926
3504 AA  Utrecht        3542 AB  Utrecht        Fax
030-2477900

zakelijk mailto:Huub.Daems@selektvracht.nl
privé mailto:h.daems1@wanadoo.nl






> -----Original Message-----
> From:    Barry Lind [SMTP:barry@xythos.com]
> Sent:    dinsdag 20 november 2001 18:34
> To:    Daems, Huub; pgsql-jdbc@postgresql.org
> Subject:    Re: Serialize its create method throws
NullPointerException
>
> There are many other frameworks out there for serializing java
objects.
>   The code in the postgres jdbc driver isn't very good, and will
> likely
> be removed in the next release.  Depending on what you are trying to
do,
> I would start with the Java2 serialization code and store the result
in
> a bytea column.
>
> thanks,
> --Barry
>
>
>
> Daems, Huub wrote:
>
> > Hi,
> >
> > does some one has a clou how to use org.postgresql.util.Serialize to
> create
> > a table from my class....
> >
> >
> > package kermitserver.PL;
> >
> > import java.io.*;
> > import java.util.*;
> > import java.sql.*;
> > import org.postgresql.util.Serialize;
> >
> >
> > public class Jk implements Serializable {
> >
> >     public int oid;
> >
> >     public Jk() {
> >     }
> >
> >     public static void main(String[] args) {
> >         Jk jk1 = new Jk();
> >         jk1.oid = 0;   // just in case, only for this test
> >
> >     try {
> >         Class.forName("org.postgresql.Driver");
> >         Connection db =
> > DriverManager.getConnection("jdbc:postgresql:kermitserver", "huub",
> > "secret");
> >
> >
> > org.postgresql.util.Serialize.create((org.postgresql.Connection)db,
> jk1);
> >
> >         db.close();
> >
> >     } catch (ClassNotFoundException cnfe) {
> >         cnfe.printStackTrace();
> >     } catch (SQLException sq) {
> >         sq.printStackTrace();
> >     } catch (NullPointerException npe) {
> >         npe.printStatckTrace();
> >     }
> > }
> >
> >
> > Try to run it and it gave an NullPointerException:
> >
> >     java.lang.NullPointerException
> >     at org.postgresql.jdbc2.ResultSet.getString(ResultSet.java:171))
> >     at org.postgresql.util.Serialize.create(Serialize.java:241)
> >     at org.postgresql.util.Serialize.create(Serialize.java:220)
> >     at kermitserver.PL.jk.main(jk.java:37)
> >
> > I am wondering what the ResultSet is doing.
> > I am using jdk1.3.1_01 from Sun, jdbc7.1-1.2.jar on postgresql 7.1.3
on
> SuSe
> > 7.3
> >
> > Would be nice if someone has an idea....
> >
> > greeting Huub
> >
> >
> >
> >
> >
> >
> > ---------------------------(end of
> > broadcast)---------------------------
> > TIP 3: if posting/reading through Usenet, please send an appropriate
> > subscribe-nomail command to majordomo@postgresql.org so that your
> > message can get through to the mailing list cleanly
> >
> >
>

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster