Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Serializing a static object question and NotSerializableException  RSS feed

 
Mahmoud Hadad
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read the ObjectOutputStream and saw that static and tranient fields can not be serialized so i tryed serializing an int variable then deserializing this variable from the same class and it did work.anyway i'm developing a mechanism for auto saving changes done to a db in my Application.The mechanism is somewhat complicated.anyway i'm calling a method on a static object from a class beside the one holding this object.it is something like this GeneralFrame.chaneges.addChanges(aStringValue);
GeneralFrame contains a static object called changes which is of type DBChanges.the DBChanges class implements Serializable.i'm calling this method from a class called GeneralFrameTableModel which is the model for my JTable.anyway it throws this Exception:

java.io.NotSerializableException: sun.jdbc.odbc.JdbcOdbcConnection

anyideas on why it is throwing this exception?
 
Mahmoud Hadad
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i do call GeneralFrame.changes.addChanges(aStringValue)
it executes the method statementObject.addBatch(theStringValue);
but in muliple times.so this might be throwing exceptions not my streams
mechanism???
 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mahmoud!!!
i think problem is with connection obj which is not serilizable if u are containing this obj in ur serilized Object it will throw the exception which u have mentioned!!!

With Best Regards,
Sachin!!!
 
Mahmoud Hadad
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in DBChanges constructor i have a Connection object as a parameter.
and as i know Statement objects are not serializable.so which is the cause of the exception?because my DBChanges constructor takes a Connection object or because it is trying to serialize a Statement object?
 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Mahmoud, if u make u r connection object serilizable(by anyway) it will show exception to statement!!! so the exception is at connection object.

With Best Regards,
Sachin!!!
 
Mahmoud Hadad
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so i might put my SQL statements into an ArrayList Object then keep serializing my ArrayList Object using ObjectOutputStream stream and when i need to add them as a JDBC Batch i should keep calling statementObject.addBatch(aStringValue) then call statementObject.executeBatch(),right?
 
Mahmoud Hadad
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok serializing a static ArrayList object worked for me.Thanks for replying so fast sachin.you really were great.
Thanks again,
Mahmoud Hadad
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!