Esempio n. 1
0
 @Override
 public synchronized ResultMessage cancelCollect(String bookISBN, int memberID) {
   ResultMessage isExist = queryCollect(memberID, bookISBN);
   if (!isExist.isInvokeSuccess()) {
     return new ResultMessage(false, null, "未曾收藏此书");
   }
   Connection con = ConnectionFactory.getConnection();
   String sql = "delete from collect where memberid=? and bookisbn=?";
   PreparedStatement ps;
   int row = 0;
   try {
     ps = con.prepareStatement(sql);
     ps.setInt(1, memberID);
     ps.setString(2, bookISBN);
     row = ps.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   try {
     con.close();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   if (row != 0) {
     return new ResultMessage(true, null, "删除收藏成功");
   }
   return new ResultMessage(false, null, "删除收藏失败");
 }
Esempio n. 2
0
 @Override
 public synchronized ResultMessage bookCollect(String bookISBN, int memberID) {
   ResultMessage isExist = queryCollect(memberID, bookISBN);
   if (isExist.isInvokeSuccess()) {
     return new ResultMessage(false, null, "已经收藏此书");
   }
   ResultMessage booknum = getCollectedBook(memberID);
   if (booknum.isInvokeSuccess() && booknum.getResultSet().size() >= Const.MAX_COLLECT) {
     return new ResultMessage(false, null, "已达书架上线,无法收藏更多图书");
   }
   Connection con = ConnectionFactory.getConnection();
   String sql = "insert into collect(memberid,bookisbn) values (?,?)";
   PreparedStatement ps;
   int row = 0;
   try {
     ps = con.prepareStatement(sql);
     ps.setInt(1, memberID);
     ps.setString(2, bookISBN);
     row = ps.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   try {
     con.close();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   if (row != 0) {
     return new ResultMessage(true, null, "收藏成功!");
   }
   return new ResultMessage(false, null, "收藏失败");
 }