public static Pagelist<Books> Serchbooks(int page, int numItemsInPage,
			String sbook) throws NamingException, SQLException {
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		if (page <= 0) {
			page = 1;
		}
		if (sbook == null) {
			sbook = "";
		} else {
			sbook = "%" + sbook + "%";
		}

		DataSource ds = getDataSource();
		Pagelist<Books> result = new Pagelist<Books>(numItemsInPage, page);

		int startPos = (page - 1) * numItemsInPage;

		try {
			conn = ds.getConnection();
			stmt = conn
					.prepareStatement("SELECT count(*) FROM books where b_name like ?");
			stmt.setString(1, sbook);
			rs = stmt.executeQuery();

			rs.next();

			result.setNumItems(rs.getInt(1));

			rs.close();
			rs = null;
			stmt.close();
			stmt = null;

			stmt = conn
					.prepareStatement("SELECT * FROM books where b_name like ? LIMIT "
							+ startPos + ", " + numItemsInPage);
			stmt.setString(1, sbook);

			rs = stmt.executeQuery();

			while (rs.next()) {
				result.getList().add(
						new Books(rs.getInt("b_number"),
								rs.getString("b_name"), rs.getString("writer"),
								rs.getString("maker"), rs.getDate("b_date"), rs
										.getString("category"), rs
										.getInt("isbn"), rs
										.getString("location")));
			}
		} finally {
			if (rs != null)
				try {
					rs.close();
				} catch (SQLException e) {
				}
			if (stmt != null)
				try {
					stmt.close();
				} catch (SQLException e) {
				}
			if (conn != null)
				try {
					conn.close();
				} catch (SQLException e) {
				}
		}

		return result;
	}