求助!谢谢各位好心人
public boolean addnew(HttpServletRequest newrequest) {request = newrequest;
String ID = request.getParameter("bookid");
String Amount = request.getParameter("amount");
long bookid = 0;
int amount = 0;
try {
bookid = Long.parseLong(ID);
amount = Integer.parseInt(Amount);
}
catch (Exception e) {
return false;
}
if (amount < 1)
return false;
session = request.getSession(false);
if (session == null) {
return false;
}
purchaselist = (ArrayList) session.getAttribute("shopcar");
sqlStr = "select leav_number from book where id=" + bookid;
try {
DataBase db = new DataBase();
Connection conn=db.connect();
stmt = conn.createStatement ();
rs = stmt.executeQuery(sqlStr);
if (rs.next()) {
if (amount > rs.getInt(1)) {
leaveBook = rs.getInt(1);
isEmpty = true;
return false;
}
}
rs.close();
}
catch (SQLException e) {
return false;
}
allorder iList = new allorder();
iList.setBookNo(bookid);
iList.setAmount(amount);
boolean match = false;
if (purchaselist == null) {
purchaselist = new ArrayList();
purchaselist.add(iList);
}
else {
for (int i = 0; i < purchaselist.size(); i++) {
allorder itList = (allorder) purchaselist.elementAt(i);
if (iList.getBookNo() == itList.getBookNo()) {
itList.setAmount(itList.getAmount() + iList.getAmount());
purchaselist.setElementAt(itList, i);
match = true;
break;
}
}在代码中为啥提示elementAt(i);和setElementAt(itList, i);这两处有错误 --------------------编程问答-------------------- 请分清是List还是Vector
List对象用get和set方法
--------------------编程问答-------------------- 逻辑有点乱,没看懂啥意思 --------------------编程问答-------------------- 但还是要谢谢你!
补充:Java , Web 开发