package bookshop.run;
import java.sql.*;
import java.util.ArrayList;
import bookshop.util.*;
import bookshop.book.*;
import javax.servlet.http.*;
import java.util.*;
public class op_buy extends DataBase{
    private javax.servlet.http.HttpServletRequest request;
    private HttpSession session;
    private boolean sqlflag = true;
    private ArrayList purchaselist;
     private ArrayList order_list;
    private int booknumber = 0;
    private float all_price = 0;
    private boolean isEmpty = false;
    private int leaveBook = 0;
    private String orderId = "";
    private boolean isLogin = true;
    private int page = 1;
    private int pageSize = 15;
    private int pageCount = 0;
    private long recordCount = 0;
    
    Calendar date = Calendar.getInstance();
    long time=date.getTimeInMillis();
    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);//这提示elementAt cannot find symbol为啥啊
          if (iList.getBookNo() == itList.getBookNo()) {
            itList.setAmount(itList.getAmount() + iList.getAmount());
            purchaselist.setElementAt(itList, i);//这这提示setElementAt  cannot find symbol
            match = true;
            break;
          }
           }
          if (!match)
          purchaselist.add(iList);
      }
      session.setAttribute("shopcar", purchaselist);
      return true;
    }public boolean modiShoper(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");
      if (purchaselist == null) {
        return false;
      }
      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;
      }
      for (int i = 0; i < purchaselist.size(); i++) {
        allorder itList = (allorder) purchaselist.elementAt(i);//这提示elementAt cannot find symbol
        if (bookid == itList.getBookNo()) {
          itList.setAmount(amount);
          purchaselist.setElementAt(itList, i);//这这提示setElementAt  cannot find symbol
          break;
        }
          }
       return true;
    }
各位问题已经在错误的地方标注了!谢谢了!急用!跪求

解决方案 »

  1.   

    allorder是什么啊,还有LZ继承的DataBase是什么
      

  2.   

    public class DataBase {
      public Connection conn;
      public Statement stmt;
      public ResultSet rs=null;
      public String sqlStr="";
      
      public Connection connect(){
          try{
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
            String url ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bookshop";
            conn=DriverManager.getConnection(url,"sa","");
            stmt = conn.createStatement ();
           }catch(Exception ee){
            System.out.println("connect db error:"+ee.getMessage());
           }
          return conn;
        }
     }
    这是sql
        
       public allorder() {
                    Id = 0;
                    orderId = 0;
                    BookNo = 0;
                    Amount = 0;
            }
            public long getId() {
                    return Id;
            }
            public void setId(long newId) {
                    this.Id = newId;
            }
            public long getOrderId() {
                    return orderId;
            }
            public void setOrderId(long orderId) {
                    this.orderId = orderId;
            }
            public long getBookNo() {
                    return BookNo;
            }
            public void setBookNo(long newBookNo) {
                    this.BookNo = newBookNo;
            }
            public int getAmount() {
                    return Amount;
            }
            public void setAmount(int newAmount) {
                    this.Amount = newAmount;
            }  
    }
    这是allorder
    谢谢了