From: | "Dave Cramer" <Dave(at)micro-automation(dot)net> |
---|---|
To: | "'candreol'" <Christophe(dot)Andreoli(at)consol(dot)de>, <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | RE: problem with serialization |
Date: | 2001-07-27 01:39:45 |
Message-ID: | 021c01c1163d$0474e3b0$8201a8c0@inspiron |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Chris,
This will work, the fields have to be public to for introspection
/*
* 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(at)postgresql(dot)org
[mailto:pgsql-jdbc-owner(at)postgresql(dot)org] On Behalf Of candreol
Sent: July 26, 2001 4:02 AM
To: dave(at)fastcrypt(dot)com; pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [JDBC] problem with serialization
Hi Dave,
thank you!
It would be nice if you fix it. I had some problems with compiling , I
would be very happy if could send me a new jar.
chris
Dave Cramer wrote:
That is definately a bug. Chris; do you have a way to compile the
source? I can fix it and provide you with a driver to test if you need
?Dave
-----Original Message-----
From: Nandu [mailto:cr_nandu(at)yahoo(dot)com]
Sent: July 26, 2001 4:32 AM
To: candreol; Dave(at)micro-automation(dot)net; pgsql-jdbc(at)postgresql(dot)org
Subject: RE: [JDBC] problem with serialization
I think i know the problem, as the Serialise class of postgres there is
a line of code which will never work.It is like:if(!rs.next()) {
// they print something here like System.out.println(" Driver
Manager: " + rs.getString()) //which will always be null because
getString() will return null when rs.next() == false}I feel that it is a
bug with the Serialise implementation in postgresComment that line out
and u won't get Null pointer problem.Cheers,Nandu.
-----Original Message: pgsql-jdbc-owner(at)postgresql(dot)org
[mailto:pgsql-jdbc-owner(at)postgresql(dot)org]On Behalf Of candreol
Sent: 26 July 2001 07:35
To: Dave(at)micro-automation(dot)net; pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [JDBC] problem with serialization
Hi Dave,
The code is very small. It is just a test :
/*
* Java sample program
*/
import java.io.*;
import java.sql.*;
import org.postgresql.util.Serialize;
public class lili implements Serializable
{
String myString;
int myNumber;
public lili() throws ClassNotFoundException,
FileNotFoundException, IOException, SQLException
{
myString="theString";
myNumber=4;
}
private void testmethod(){};
public void testmethod2x(){};
public static void main(String args[])
{
try {
lili mylili = new lili();
Class.forName("org.postgresql.Driver"); //
load database interface
// connect to the database
org.postgresql.Connection conn =
(org.postgresql.Connection)DriverManager.getConnection("jdbc:postgresql:
//localhost:5432/onlinechess", "postgres", "mypassword"); // works
// test of serialisation
org.postgresql.util.Serialize.create(conn, mylili); // makes
problems
} catch(Exception exc)
{
System.err.println("Exception caught.\n" + exc);
exc.printStackTrace();
}
}
}
Dave Cramer wrote:
Chris,
Can you send us your code. Or a snippet?
Dave
Hi! I am new here.
I did a small test to try object serialization with the
org.postgresql.util.Serialize class.
I get the following exception when I try to use the at
org.postgresql.util.Serialize.create Method. :
java.lang.NullPointerException
at org.postgresql.jdbc2.ResultSet.getString(ResultSet.java:148)
at org.postgresql.util.Serialize.create(Serialize.java:241)
at org.postgresql.util.Serialize.create(Serialize.java:220)
I looked at create in Serialization.java and saw that
the exception occurs at getString although I have no table corresponding
to the class I want to serialize.
if(!rs.next()){
// String lolo=rs.getString(1);}
}
Although the resultset is empty (because the table is absent) , why
getString has been run ?
Can you help me ?
Chris
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
From | Date | Subject | |
---|---|---|---|
Next Message | Daniel Fisher | 2001-07-27 15:59:54 | Large Objects |
Previous Message | Bruce Momjian | 2001-07-26 20:59:06 | Re: [SQL] Re: When PostgreSQL compliant JDBC 2.0? |