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

NotSerializableException Problem  RSS feed

 
Jack Nicholson
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am running my(JSP-BEANS) application in Tomcat 4.1.12 webserver.
Whenever I invoke my beans, on server side i am getting strange exceptions, can any body tell me about this & how to avoid it?
The Exceptions are
2002-11-06 09:15:10 StandardManager[/examples] Cannot serialize session attribute objHits for session EF2484543BE751E096D3DB0866DF5326
java.io.NotSerializableException: sun.jdbc.odbc.JdbcOdbcConnection
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
at java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1841)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:480)
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1214)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
at org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:1427)
at org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:869)
at org.apache.catalina.session.StandardManager.unload(StandardManager.java:507)
at org.apache.catalina.session.StandardManager.stop(StandardManager.java:662)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:3591)
at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:1036)
at org.apache.catalina.core.StandardHostDeployer.remove(StandardHostDeployer.java:420)
at org.apache.catalina.core.StandardHost.remove(StandardHost.java:852)
at org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:919)
at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:899)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:370)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:166)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1221)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1233)
at org.apache.catalina.core.StandardService.stop(StandardService.java:554)
at org.apache.catalina.core.StandardServer.stop(StandardServer.java:2224)
at org.apache.catalina.startup.Catalina.start(Catalina.java:541)
at org.apache.catalina.startup.Catalina.execute(Catalina.java:400)
at org.apache.catalina.startup.Catalina.process(Catalina.java:180)
at java.lang.reflect.Method.invoke(Native Method)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)
& other error is
2002-11-06 09:16:46 StandardManager[/examples] IOException while loading persisted sessions: java.io.WriteAbortedException: Writing aborted by exception; java.io.NotSerializableException: sun.jdbc.odbc.JdbcOdbcConnection
java.io.WriteAbortedException: Writing aborted by exception; java.io.NotSerializableException: sun.jdbc.odbc.JdbcOdbcConnection
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:445)
at java.io.ObjectInputStream.inputClassFields(ObjectInputStream.java:2262)
at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:519)
at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1411)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
at org.apache.catalina.session.StandardSession.readObject(StandardSession.java:1357)
at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:852)
at org.apache.catalina.session.StandardManager.load(StandardManager.java:411)
at org.apache.catalina.session.StandardManager.start(StandardManager.java:626)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3496)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:738)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:347)
at org.apache.catalina.core.StandardService.start(StandardService.java:497)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2189)
at org.apache.catalina.startup.Catalina.start(Catalina.java:510)
at org.apache.catalina.startup.Catalina.execute(Catalina.java:400)
at org.apache.catalina.startup.Catalina.process(Catalina.java:180)
at java.lang.reflect.Method.invoke(Native Method)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)

To the strange , the error occurs at the same line in beans is -
---> psmt = con.prepareStatement( sqlQuery );
I am using following super class to establish the connection. (using extends ConnectionEst in each class)
public class ConnectionEst {
Connection con= null;
synchronized public Connection getConObject() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection ("jdbc dbc oll","","");
System.out.println("Connection Established ");
}catch(Exception ex){
ex.printStackTrace();
}
return con ;
}
}
As I want to save the state of beans to the extent of session, I am using Serializable interface for each class.
& using following methods to establish connection & execute SQl Queries in beans -
public void getQuestionSet() {
String sqlQuery="";
int iOption;
int j=0;
try {
if(con==null)
con = getConObject() ;
sqlQuery="SELECT szQuestion, iOptions, szOption1, szOption2, szOption3,szOption4, szOption5 FROM QuestionSetWHERE srno=? ";
psmt=con.prepareStatement(sqlQuery);
psmt.setInt( 1, iSrno );
rs = psmt.executeQuery();
if(rs.next()){
szQuestion = rs.getString("szQuestion");
}
}catch(Exception ex){
ex.printStackTrace();
}
finally {
try {
if( psmt != null ) {
psmt.close();
}
}catch(Exception ed) {
ed.printStackTrace();
}
}
}

Can any body tell me how to avoid this error message.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!