這是我的SQL連接類的代碼,我收到錯誤消息。java.sql.SQLException:參數值無效:java.io.NotSerializableException
public class SqlConnection {
static Connection con;
.......
static public ResultSet getData(String sql, List<LogModel> alist)
throws ClassNotFoundException, SQLException {
PreparedStatement pst = con.prepareStatement(sql);
if (alist != null) {
for (int i = 1; i <= alist.size(); i++) {
pst.setObject(i, alist.get(i-1)); //Exception at this Line
}
}
ResultSet rs = pst.executeQuery();
return rs;
}
}
這裏是LogAction
類我在哪裏調用這個函數getdata()
。
public class LogAction extends ActionSupport implements ModelDriven<LogModel>, Preparable {
LogModel log = null;
List<LogModel> alist = null;
public static final String FAILURE = "failure";
@Override
public void prepare() throws Exception {
log = new LogModel();
alist = new ArrayList<LogModel>();
}
@Override
public LogModel getModel() {
return log;
}
public String login() throws ClassNotFoundException, SQLException {
String sql = "Select username,password from registration where username=? and password=?";
alist.add(log);
System.out.println(alist);
ResultSet rs = SqlConnection.getData(sql, alist);
if (rs.next()) {
return SUCCESS;
} else
return FAILURE;
}
}
* ModelDriven是否 –
Maninder
我們可以有堆棧跟蹤嗎?當程序試圖序列化一個沒有實現Serializable的類的對象時拋出這個異常 –
LogModel是可序列化的嗎? –