Quote:
Originally posted by cesar
Hello,
I am trying to serialize a class which connects to a DB2 server. I obtain the following error: java.io.NotSerializableException: COM.ibm.db2.jdbc.app.DB2Connection
Does anybody have any idea?
Thanks,
Cesar
|
That's because you can't serialize a database connection - it is meaningles.
You could use writeObject() and readObject methods to do the following:
1) create a wrapper around the Connection class
2) in the wrapper class implement writeObject() that would write connection information (url, userid, password) instead of the Connection itself
3) also implement readObject() that reads the connection information from the deserialization stream and establishes a new Connection using those data
Look at javadoc for the Serializable interface for more information.
By the way, this has nothing to do with DB2...