⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customeroperation.java

📁 该系统实现了网上购物及书店管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			preparedStatement.setString(8, useBean.getUserAdds());
			preparedStatement.setInt(9, useBean.getUserCode());
			preparedStatement.setString(10, useBean.getUserWork());
			preparedStatement.setString(11, useBean.getUserCard());
			preparedStatement.setInt(12, useBean.getUserAge());
			preparedStatement.setInt(13, useBean.getUserId());
			// 执行更新操作
			int flag = preparedStatement.executeUpdate();
			if (flag == 0) {
				bool = false;
			}
		} catch (SQLException ex) {
			ex.printStackTrace();
			bool = false;
		}
		return bool;
	}

	/**
	 * 判断特定用户是否已经存在
	 * 
	 * @param userName
	 * @return
	 */
	public boolean hasUser(String userName) {
		boolean bool = true;
		// 查询特定用户数量的SQL语句
		String sql = "select count(*) from users where userName=?";
		try {
			// 创建Statement对象
			preparedStatement = connection.prepareStatement(sql);
			// 设置Statement对象的相关参数
			preparedStatement.setString(1, userName);
			// 执行查询
			resultSet = preparedStatement.executeQuery();
			resultSet.next();
			int flag = resultSet.getInt(1);
			if (flag > 0) {
				bool = true;
			} else {
				bool = false;
			}
		} catch (SQLException ex) {
			ex.printStackTrace();
			bool = true;
		}

		return bool;
	}

	/**
	 * 根据bookID取得相应的图书信息
	 * 
	 * @param bookId
	 * @return
	 */
	public BookBean getBookBean(String bookId) {
		BookBean bbean = new BookBean();
		// 查询图书信息的SQL语句
		String sql = "select * from information where BookId=?";
		try {
			// 创建Statement对象
			preparedStatement = connection.prepareStatement(sql);
			// 设置Statement对象相应的参数
			preparedStatement.setString(1, bookId);
			// 执行查询操作
			resultSet = preparedStatement.executeQuery();
			while (resultSet.next()) {
				bbean.setBookCompany(resultSet.getString("BookCompany"));
				bbean.setBookCount(1);
				bbean.setBookData(resultSet.getDate("BookDate"));
				bbean.setBookId(Integer.parseInt(bookId));
				bbean.setBookImage(resultSet.getString("BookImage"));
				bbean.setBookName(resultSet.getString("BookName"));
				bbean.setBookPenster(resultSet.getString("BookPenster"));
				bbean.setBookPrice(resultSet.getInt("BookPrice"));
				bbean.setBookSell(resultSet.getInt("BookSell"));
				bbean.setBookStep(resultSet.getInt("BookStep"));
				bbean.setBookStorage(resultSet.getInt("BookStorage"));
				bbean.setBookSynopsis(resultSet.getString("BookSynopsis"));
				bbean.setBookType(this.queryType(""
						+ resultSet.getInt("BookType")));
				bbean.setBookAllPrice(bbean.getBookPrice());
			}
		} catch (SQLException ex) {
			ex.printStackTrace();
			return null;
		}
		return bbean;
	}

	/**
	 * 查询等级信息
	 * 
	 * @param typeId
	 * @return
	 */
	public String queryType(String typeId) {
		try {
			// 创建Statement对象,从Type表中查询等级属性
			java.sql.PreparedStatement prepar1 = connection
					.prepareStatement("select Display from Type where TypeId=?");
			// 设置Statement对象的相应参数
			prepar1.setInt(1, Integer.parseInt(typeId));
			// 执行查询
			ResultSet res1 = prepar1.executeQuery();
			res1.next();
			return res1.getString("Display");
		} catch (SQLException ex) {

			return null;
		}
	}

	public int getPageCount(int page, int bookNum, int bookType, int bookStep) {
		int count = 0;
		try {
			callableStatement = connection
					.prepareCall("{call proc_page (?,?,?,?,?)}");

			callableStatement.setInt(1, page);
			callableStatement.setInt(2, bookNum);
			callableStatement.setInt(3, bookType);
			callableStatement.setInt(4, bookStep);
			callableStatement.registerOutParameter(5, Types.INTEGER);
			callableStatement.execute();
			count = callableStatement.getInt(5);

		} catch (SQLException ex) {
			ex.printStackTrace();
		}
		return count;
	}

	public ArrayList getPageData(int page, int bookNum, int bookType,
			int bookStep) // 取出分页的记录
	{
		ArrayList bookList = new ArrayList(); // 返回的分页的List数据
		System.out.println(bookNum + "    ");
		// 需要填充的bookBean book的信息
		try {
			callableStatement = connection
					.prepareCall("{call proc_page(?,?,?,?,?)}"); // 存储过程 分页
			// proc_page(?,?,?,?)
			callableStatement.setInt(1, page); // 参数1 第几页
			callableStatement.setInt(2, bookNum); // 参数2 多少个结果
			callableStatement.setInt(3, bookType); // 参数3 书的类型
			callableStatement.setInt(4, bookStep);
			callableStatement.registerOutParameter(5, Types.INTEGER); // OUTPUT参数
			// 返回结构共多少页
			resultSet = callableStatement.executeQuery(); // 接收存储过程的结果集
			while (resultSet.next()) // 提取结果集的每条记录(主要问题在这里!!!!!!)
			{

				BookBean bbean = new BookBean();
				bbean.setBookName(resultSet.getString("bookName"));
				bbean.setBookId(resultSet.getInt("BookId"));

				bbean.setBookPenster(resultSet.getString("BookPenster"));
				bbean.setBookCompany(resultSet.getString("BookCompany"));
				bbean.setBookData(resultSet.getDate("BookDate"));
				bbean.setBookImage(resultSet.getString("BookImage"));

				bbean.setBookPrice(resultSet.getInt("BookPrice"));
				bbean.setBookSell(resultSet.getInt("BookSell"));
				bbean.setBookStep(resultSet.getInt("BookStep"));
				bbean.setBookStorage(resultSet.getInt("BookStorage"));
				bbean.setBookSynopsis(resultSet.getString("BookSynopsis"));
				bbean.setBookType(queryType("" + resultSet.getInt("BookType")));
				/*   */
				bookList.add(bbean); // 加入到booklist
			}
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
		return bookList;

	}

	public int getSearchCountPage() {
		return this.pagecount;
	}

	public int getSearchCountdata() {
		return this.pagedata;
	}

	public ArrayList getSearchPage(int page, int bookNum, String action,
			String searchkey, String stepid, String typeid) {

		ArrayList bookList = new ArrayList();
		try {
			callableStatement = connection
					.prepareCall("{call proc_searchpage(?,?,?,?,?,?,?,?)}");
			callableStatement.setInt(1, page); // 参数1 第几页
			callableStatement.setInt(2, bookNum); // 参数2 多少个结果
			callableStatement.setInt(3, Integer.parseInt(typeid)); // 参数3 书的类型
			callableStatement.setInt(4, Integer.parseInt(stepid));
			callableStatement.setString(5, searchkey);
			callableStatement.setString(6, action);
			callableStatement.registerOutParameter(7, Types.INTEGER); // OUTPUT参数
			// 返回结构共多少页
			callableStatement.registerOutParameter(8, Types.INTEGER);
			resultSet = callableStatement.executeQuery(); // 接收存储过程的结果集
			while (resultSet.next()) // 提取结果集的每条记录(主要问题在这里!!!!!!)
			{
				BookBean bbean = new BookBean();
				bbean.setBookId(resultSet.getInt("BookId"));
				bbean.setBookName(resultSet.getString("BookName"));
				bbean.setBookPenster(resultSet.getString("BookPenster"));
				bbean.setBookCompany(resultSet.getString("BookCompany"));
				bbean.setBookData(resultSet.getDate("BookDate"));
				bbean.setBookImage(resultSet.getString("BookImage"));
				bbean.setBookPrice(resultSet.getInt("BookPrice"));
				bbean.setBookSell(resultSet.getInt("BookSell"));
				bbean.setBookStep(resultSet.getInt("BookStep"));
				bbean.setBookStorage(resultSet.getInt("BookStorage"));
				bbean.setBookSynopsis(resultSet.getString("BookSynopsis"));
				bbean.setBookType(queryType("" + resultSet.getInt("BookType")));
				/*   */
				bookList.add(bbean); // 加入到booklist
			}
			pagecount = callableStatement.getInt(7);
			pagedata = callableStatement.getInt(8);
		} catch (SQLException ex) {
			ex.printStackTrace();
		}

		return bookList;
	}

	public String getDate() {
		SimpleDateFormat lFormat;
		Calendar MyDate = Calendar.getInstance();
		MyDate.setTime(new java.util.Date());
		java.util.Date date = MyDate.getTime();
		// 格式可以自己根据需要修改
		lFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		String gRtnStr = lFormat.format(date);
		return gRtnStr;
	}

	/**
	 * 插入定单信息
	 * 
	 * @param ofb
	 * @return
	 */
	public boolean insertOrder(OrderFormBean ofb) {
		int flag = 0;
		try {
			// 创建Statement对象,向OrderForm表中插入一条新记录
			preparedStatement = connection
					.prepareStatement("insert into OrderForm(UserId,BookId,amount,OrderData,money) values(?,?,?,?,?)");
			// 设置其相应的参数
			preparedStatement.setInt(1, ofb.getUserId());
			preparedStatement.setInt(2, ofb.getBookId());
			preparedStatement.setInt(3, ofb.getAmount());
			preparedStatement.setString(4, ofb.getOrderData());
			preparedStatement.setInt(5, ofb.getMoney());
			// 执行更新
			flag = preparedStatement.executeUpdate();
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
		if (flag > 0) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 关闭与数据库的连接
	 */
	public void Close() {
		try {
			if (resultSet != null) {
				// 关闭ResultSet
				resultSet.close();
			}
			if (preparedStatement != null) {
				// 关闭Statement对象
				preparedStatement.close();
			}
			if (connection != null) {
				// 关闭Connection对象
				connection.close();
			}
		} catch (SQLException ex) {
			ex.printStackTrace();
		}

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -