How to handle java.io.InvalidClassException?

Hamza

Please tell me what i do this exception is coming and and i don't know how to remove it

java.io.InvalidClassException: applyonline.Applicant; local class incompatible: stream classdesc serialVersionUID = 8333391523914038903, local class serialVersionUID = -6432228733925744354

    public class Applicant implements Serializable{

        public String getId() {
            return id;
        }

        public String getPassword() {
            return password;
        }

        public void setId(String id) {
            this.id = id;
        }

        public void setPassword(String password) {
            this.password = password;
        }

        public Applicant() {
        }
        public boolean checkLogin(String id,String pasword) throws SQLException, IOException, ClassNotFoundException
        {
            db dbhandlerobj=new db();
            ArrayList<Object> appList;
 /*  ----> */   appList = dbhandlerobj.getObject("Applicant","ApplicantInfo"); /* <------*/
            for(Object obj: appList)
            {
                Applicant app=(Applicant)obj;
                System.out.println("ID:::::"+app.getId());
                if(app.getId().equals(id) && app.getPassword().equals(pasword))
                {
                    return  true;
                }
            }
            return false;
        }
        private String id;
        private String password;
    }

OR Mapper class

public class db {
    Connection con;
    String host="jdbc:derby://localhost:1527/Hamza";
    String userName="Hamza";
    String pasword="123";
    public db() throws SQLException {

        this.con =DriverManager.getConnection(host, userName, pasword);
    }
    public void storeObject(Object object,String name) throws IOException, SQLException
    {
        PreparedStatement ps;
        ByteArrayOutputStream baos =new ByteArrayOutputStream();
        ObjectOutputStream obos=new ObjectOutputStream(baos);
        obos.writeObject(object);
        obos.flush();
        obos.close();
        baos.close();
        byte []data=baos.toByteArray();
        String sql="insert into "+name+" values(?)";
        ps=con.prepareStatement(sql);
        ps.setObject(1,data);
        ps.executeUpdate();
    }
    public ArrayList<Object> getObject(String tableName,String columnName) throws SQLException, IOException, ClassNotFoundException 
    {
        PreparedStatement ps;
        String sql="select * from "+tableName;
        ps=con.prepareStatement(sql);
        ResultSet rs=ps.executeQuery();
        ArrayList<Object> studentList=new ArrayList<Object>();
        while(rs.next())
        {
            try (ByteArrayInputStream bais = new ByteArrayInputStream(rs.getBytes(columnName))) {
                ObjectInputStream obis;
                obis = new ObjectInputStream(bais);
                studentList.add((Object)obis.readObject()); //<----ERROR IN THIS METHOD
            }
        }        
        return studentList;
    }  
}**
galovics

You are using a different version of the Applicant class. Maybe you first wrote the Applicant class object to the database and after that, you modified the class. That's why you are getting this message.

Write the object to the database again and then try to deserialize it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Spark: java.io.InvalidClassException

From Dev

how resolve java.io.InvalidClassException: local class incompatible: stream classdesc serialVersionUID

From Dev

Getting a java.io.InvalidClassException when trying to save and read a file

From Dev

Standalone spark cluster. Can't submit job programmatically -> java.io.InvalidClassException

From Dev

How to use catch with IO Handle

From Dev

Java - InvalidClassException local class incompatible serialVersionUID

From Dev

How to handle null value in realm.io?

From Dev

How to handle this simple IO exception in Haskell

From Dev

How to handle this simple IO exception in Haskell

From Dev

How to reregister for IO Completion ports for a handle

From Dev

How to Handle events in Java?

From Dev

How to handle exception in java

From Dev

How to handle ArrayIndexedBoundexception in Java

From Dev

How to handle Exception in Java JDBC?

From Dev

How to handle Currency in Java 8?

From Dev

java ExecutorService how to handle timeouts

From Dev

How to handle Github Webhook in Java?

From Dev

how to handle java null values

From Dev

How to properly handle create and update for realm.io relationships

From Dev

How to handle client-sessions in socket.io

From Dev

How to handle socket.io disconnect by client by leaving page?

From Dev

Socket.io : How to handle/manage multiple clients requests and responses?

From Dev

Socket.IO - how to handle Node.js offline

From Dev

how to handle page reload in socket.io client chat applications

From Dev

How to handle io.use middleware to capture errors on client?

From Dev

How to handle in Reactor Netty an io.netty.channel.ConnectTimeoutException

From Dev

How should I handle text IO in custom command line?

From Dev

How to handle client-sessions in socket.io

From Dev

How to handle io.use middleware to capture errors on client?

Related Related

  1. 1

    Spark: java.io.InvalidClassException

  2. 2

    how resolve java.io.InvalidClassException: local class incompatible: stream classdesc serialVersionUID

  3. 3

    Getting a java.io.InvalidClassException when trying to save and read a file

  4. 4

    Standalone spark cluster. Can't submit job programmatically -> java.io.InvalidClassException

  5. 5

    How to use catch with IO Handle

  6. 6

    Java - InvalidClassException local class incompatible serialVersionUID

  7. 7

    How to handle null value in realm.io?

  8. 8

    How to handle this simple IO exception in Haskell

  9. 9

    How to handle this simple IO exception in Haskell

  10. 10

    How to reregister for IO Completion ports for a handle

  11. 11

    How to Handle events in Java?

  12. 12

    How to handle exception in java

  13. 13

    How to handle ArrayIndexedBoundexception in Java

  14. 14

    How to handle Exception in Java JDBC?

  15. 15

    How to handle Currency in Java 8?

  16. 16

    java ExecutorService how to handle timeouts

  17. 17

    How to handle Github Webhook in Java?

  18. 18

    how to handle java null values

  19. 19

    How to properly handle create and update for realm.io relationships

  20. 20

    How to handle client-sessions in socket.io

  21. 21

    How to handle socket.io disconnect by client by leaving page?

  22. 22

    Socket.io : How to handle/manage multiple clients requests and responses?

  23. 23

    Socket.IO - how to handle Node.js offline

  24. 24

    how to handle page reload in socket.io client chat applications

  25. 25

    How to handle io.use middleware to capture errors on client?

  26. 26

    How to handle in Reactor Netty an io.netty.channel.ConnectTimeoutException

  27. 27

    How should I handle text IO in custom command line?

  28. 28

    How to handle client-sessions in socket.io

  29. 29

    How to handle io.use middleware to capture errors on client?

HotTag

Archive