Hi !

I am connecting to a database in an applet. After I come out of the applet,
I want to save the Connection object so that another applet can use it. I
tried to save the Connection object using Serializable interface but got the
"java.io.NotSerializableException: sun.jdbc.odbc.JdbcOdbcConnection"
exception at run time. So I assume Connection is not an Serializable object.
So I created an Serializable class with a connection object as one of the
member and tried to save this new Searizable class. But I again got the same
exception. So I assume that all the member of a serializable class has to be
Serializable.

Can u please tell me if my above conclusions are correct. If not can u tell
me what may be wrong. And if yes.... well can u advise me of any other
method to achieve my objective.

Thanks and Regards

Sameer

class temp implements Serializable
{

  Connection con;

  public void setCon(String login, String password)
  {

         try
         {
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         }
         catch(java.lang.ClassNotFoundException e)
         {
               System.out.println("ClassNotFoundException :  ");
               System.out.println(e.getMessage());
               return;
         }
         try
         {
           con =
DriverManager.getConnection("jdbc:odbc:test",login,password);
         }
         catch(SQLException ex)
         {
            System.out.println("SQLException : " + ex.getMessage());
         }
  }

  public Connection getCon()
  {
      return con;
  }
}

public class Description extends Applet implements Serializable
{

   Connection con;
   temp conTemp = new temp();

     public void init()
     {

           conTemp.setCon("login","password");
           con = conTemp.getCon();

           try
           {
               FileOutputStream fOut = new FileOutputStream("samTest.out");
               ObjectOutput out = new ObjectOutputStream(fOut);
               out.writeObject(conTemp);
               out.flush();
               out.close();
           }
           catch(FileNotFoundException e)
           {
                System.out.println("File not found error. Error message : "
+ e.getMessage());
           }
           catch(IOException e)
           {
                System.out.println("I/O Exception. Error message : " +
e.getMessage());
           }

}

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to