op_bookclass.java
上传用户:tanyanyong
上传日期:2013-06-23
资源大小:1355k
文件大小:4k
源码类别:

电子政务应用

开发平台:

MultiPlatform

  1. package bookshop.run;
  2. /**
  3.  * <p>Title: </p>
  4.  */
  5. import java.util.*;
  6. import bookshop.util.*;
  7. import bookshop.book.*;
  8. import java.sql.*;
  9. import java.lang.String;
  10. import javax.servlet.http.HttpServletRequest;
  11. public class op_bookclass extends DataBase{
  12.   public op_bookclass() {
  13.   }
  14.   private bookclass bookclass = new bookclass(); //新的图书分类
  15.   private javax.servlet.http.HttpServletRequest request; //建立页面请求
  16.   private Vector classlist; //图书类别向量数组
  17.   public Vector getClasslist() {
  18.         return classlist;
  19.           }
  20.   public String getBookClassSql() {
  21.                   sqlStr = "select id,classname from bookclass order by id";
  22.                   return sqlStr;
  23.           }
  24.           //查询图书分类
  25.   public boolean seachBookClass() throws Exception {
  26.                   int id = 0;
  27.                   String classname = "";
  28.                   int rscount = 0;
  29.                   try {
  30.                   DataBase db = new DataBase();
  31.                   db.connect();
  32.                   stmt = db.conn.createStatement ();
  33.                   rs = stmt.executeQuery(getBookClassSql());
  34.                   rscount = stmt.getMaxRows();
  35.                   classlist = new Vector(rscount+1);
  36.                   classlist.clear();
  37.                   while (rs.next()){
  38.                                   id = rs.getInt("id");
  39.                                   classname = rs.getString("classname");
  40.                                   bookclass bc = new bookclass(id,classname);
  41.                                   classlist.addElement(bc);
  42.                           }
  43.                           rs.close();
  44.                           return true;
  45.                   }
  46.                   catch (SQLException sqle){
  47.                           System.out.println(sqle);
  48.               return false;
  49.                   }
  50.           }
  51.           //添加新图书分类时获得页面转递的分类名称
  52. public boolean getRequest(javax.servlet.http.HttpServletRequest newrequest) {
  53.      boolean flag = false;
  54.      try{
  55.          request = newrequest;
  56.          String bookclassname = request.getParameter("bookclassname");
  57.           if (bookclassname==null || bookclassname.equals("")){
  58.               bookclassname = "";
  59.               flag = false;
  60.               }
  61.               bookclass.setClassName(bookclassname);
  62.               return true;
  63.           }catch (Exception e){
  64.             return false;
  65.             }
  66.     }
  67.     //添加新的图书分类
  68.         public boolean insert() throws Exception {
  69.            sqlStr = "insert into bookclass (classname) values ('";
  70.            sqlStr = sqlStr + dataFormat.toSql(bookclass.getClassName()) + "')";
  71.                       try
  72.                       {      System.out.print(sqlStr);
  73.                         DataBase db = new DataBase();
  74.                               db.connect();
  75.                               stmt =db.conn.createStatement ();
  76.                               stmt.execute(sqlStr);
  77.                               return true;
  78.                       }
  79.                       catch (SQLException sqle)
  80.                       {        System.out.print(sqle.getMessage());
  81.                               return false;
  82.                       }
  83.               }
  84.           //添加新的图书分类
  85.           public boolean delete( int aid ) throws Exception {
  86.                sqlStr = "delete from bookclass where id = "  + aid ;
  87.                try
  88.                {         DataBase db = new DataBase();
  89.                           db.connect();
  90.                           stmt =db.conn.createStatement ();
  91.                        stmt.execute(sqlStr);
  92.                        return true;
  93.                }
  94.                catch (SQLException e)
  95.                {
  96.                        System.out.println(e);
  97.                        return false;
  98.                }
  99.        }
  100.   };