0
請告訴我,我做什麼此異常快到了,我不知道如何刪除它如何處理java.io.InvalidClassException?
java.io.InvalidClassException:applyonline.Applicant;局部類 不相容:流classdesc的serialVersionUID = 8333391523914038903, 本地類的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映射器類
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;
}
}**
好的,謝謝...... – Hamza
不客氣! – galovics