Java-Business-Application/C2/Issuing-and-Returning-a-book/English-timed

From Script | Spoken-Tutorial
Jump to: navigation, search
Time Narration
00:00 Welcome to the spoken-tutorial on Issuing and returning a book.
00:05 In this tutorial, we will learn how:
00:08 To fetch all the user details
00:11 To issue a book
00:13 To return a book.
00:15 Here we are using:
00:17 Ubuntu Version 12.04
00:20 Netbeans IDE 7.3
00:23 JDK 1.7
00:25 Firefox web-browser 21.0
00:29 You can use any web-browser of your choice.
00:33 To follow this tutorial, you must have knowledge of:
00:37 Basics of Java Servlets and JSPs
00:40 Creating and viewing inventories.
00:44 If not, for relevant tutorials please visit our website.
00:48 In the earlier tutorial, we had seen how the Admin Section works.
00:53 Here, in this tutorial, we have added more functionality to the Admin Section.
00:59 So, let us switch to the browser.
01:02 Let us login again as the admin.
01:05 We can see that we have two more options in the Admin Section Page - List Users and Checkout/Return Book.
01:14 Now, let us come to the IDE.
01:18 We can see that in the adminsection.jsp there are two more radio buttons.
01:24 One for List Users and the other for Checkout/Return Book.
01:30 Now, switch back to the browser.
01:33 We will click on the radio button for List Users.
01:38 It has all the details like First Name, Surname, Age, Gender and Username.
01:48 The steps are similar to the earlier two options;
01:51 we saw them in the previous tutorial.
01:55 Now, let us click on the next option which is to Checkout or Return Book.
02:01 We get a form which allows you to checkout as well as return book.
02:06 We will now see the code for the same.
02:09 Switch back to the IDE.
02:11 We clicked on Checkout/Return Book.
02:14 So menuSelection is equal to checkoutbook.
02:18 The steps are the same that we saw for List Books.
02:23 But here, we forward the request to checkOut.jsp using RequestDispatcher.
02:29 Now, let us come to checkOut dot jsp.
02:33 This page is similar to that of listBooks dot jsp
02:38 except that we have a radio button against each book
02:42 so that we can Checkout/Return that book.
02:46 We also have a User name field to get the username of the user who has to checkout the book.
02:53 We also have a Date field to set the return date of the book.
02:59 We have set the return date as one week from current date.
03:04 This is done using the class Calendar.
03:07 The add() function of this class takes two parameters.
03:13 The first is the present day of the year.
03:16 Second is the number of days to be added to the present day.
03:21 We have added seven days.
03:23 Now, note that form action is equal to CheckOutServlet.
03:29 Now, let us come back to the browser.
03:32 We will click on Book Id 1.
03:35 Type the username as arya.
03:38 We see that the return date is one week from today’s date.
03:43 Note that the number of Available Copies is 9.
03:48 Click on Checkout book.
03:51 We get the Checkout Success Page.
03:55 We will click on here to come to the Admin Section Page.
03:59 Again click on Checkout/Return Book.
04:03 We can see that the number of Available Copies reduces to 8.
04:08 We will see the code for this now.
04:10 Come back to the IDE.
04:13 Go to CheckOutServlet.java.
04:16 We have set the errorMsgs list.
04:19 We have set the errorMsgs in the request.
04:23 We get the username from the request using getParameter.
04:28 Similarly, we get checkout_book, return_book and book-id.
04:34 Next, we parse the book_id as Integer from the id.
04:40 We validate the userName and book id.
04:44 We also validate if Checkout_book and Return_Book are null.
04:50 Then, we validate if either of them is not null.
04:55 Here, we check if the user exists in the system using userExists method.
05:01 We then store the returned value of the method in userExists variable.
05:07 Now, we will see what we do in this method.
05:11 Here, first we execute the query to check if the username exists in the table.
05:18 Then we initialize the integer variable userExists to 0.
05:23 If the username exists then we set userExists to 1.
05:29 We then return the value of userExists.
05:33 So, if the method returns 0 then it means the user does not exist in the system.
05:42 else, if user exists then we call 'bookAlreadyIssued' method.
05:50 We then store the returned value of the method in bookIssued.
05:55 Here, we check if the same book has already been issued by the same user.
06:01 Now, let us come to bookAlreadyIssued method.
06:05 Here, we have set an integer variable bookAlreadyIssued to 0.
06:12 We execute the query to check if a book with the same book_id is issued by the same user.
06:18 We get the book_id from Checkout table.
06:23 If BookId exists then set the variable bookAlreadyIssued to 1.
06:30 We then return the value of bookAlreadyIssued.
06:34 So, if the method returns 1 then it means the same user has already borrowed this book.
06:43 Now, come back to the browser.
06:46 Now, let us try to checkout the same book by the same user.
06:51 Type the username as arya.
06:54 Click on the radio button against Book Id 1.
06:59 Then click on Checkout book.
07:03 We see that we get theerror message that "The same user has already borrowed this book".
07:10 Now, switch back to the IDE.
07:14 If userExists in the system and if the checkout_book is not null, we call checkout method.
07:22 Let us see what we do in this method.
07:25 Here, we get the availablecopies for the corresponding id.
07:31 We get this from Books table.
07:35 We then store the number of availablecopies into the variable availableCopies.
07:41 We check if availableCopies is greater than 0 and bookIssued is equal to 0.
07:50 We get the dateofreturn from the request and store it in returndate.
07:56 We then call insertIntoCheckout.
08:00 We will see what we do in insertIntoCheckout method.
08:05 Here, we store the book_id, userName and returndate into the Checkout table.
08:12 Then we call decrementAvailableCopies method.
08:16 We will see what we do in this method.
08:19 Here, we execute the query to decrement the Available Copies in the Books table by 1.
08:26 Then we call the setCheckoutIntoRequest method.
08:29 Let us come to this method.
08:32 In this method, we set the checkout attribute into the request.
08:38 Then we forward the request to successCheckout.jsp using RequestDispatcher.
08:45 If availableCopies is 0 then we print "There are no copies of the requested book available".
08:53 Now, let us come to successCheckout dot jsp.
08:58 Here, first we get the checkout attribute from the request.
09:03 We then display the success message for successful Checkout.
09:08 You can try out the different errors by yourself.
09:11 Now, let us return the book. So, switch to the browser.
09:15 Click on Book Id 1 and type the username as "arya".
09:21 Then, click on Return book.
09:24 We get the success message that book has been successfully returned.
09:29 Click on here for another checkout/return.
09:33 So, we come back to Admin Section Page.
09:36 Click on Checkout/Return Book.
09:39 We can see that the number of Available Copies has been incremented.
09:45 We will see the code for this.
09:47 Come back to the IDE.
09:49 Open CheckOutServlet dot java.
09:53 We check if userExists is equal to 1 AND return_book is not equal to null.
10:00 Then we call returnBook method.
10:03 Let us come to this method.
10:06 Here, we select the totalcopies and availablecopies from Books table for the Book Id.
10:14 We store the Total Copies and Available Copies to totcopies and availcopies.
10:21 Then we check if available copies exceed the total Copies.
10:27 Now, let us come back to the browser.
10:30 Let us now return a book for a user who has not borrowed the book.
10:35 Type the User name as mdhusein.
10:39 Click on Book Id 1.
10:42 Then click on Return book.
10:44 We can see that we get the error message: "The given user has not borrowed this book!!"
10:50 Now, come back to the IDE.
10:53 Here, we check if bookIssued is equal to 1.
10:57 We then call removeFromCheckout method.
11:01 Let us come to this method.
11:04 Here, we execute the query to delete from Checkout table the entry which has returned the book.
11:14 Then, we call incrementAvailableCopies method.
11:18 Let us come to this method.
11:21 Here, we increment the Available Copies by 1.
11:25 We execute the query to update in the Books table.
11:29 Then we call the setReturnIntoRequest method.
11:34 Let us come to this method.
11:37 Here, we set the returnBook attribute into the request.
11:41 Then we forward to successReturn page using RequestDispatcher.
11:48 The successReturn page is similar to that we had for successCheckout page.
11:53 Now, come back to the browser. Come back to the login page.
11:58 We can see that we have a link called Visitor’s Home Page.
12:03 We can see that we get a list of all the books available.
12:07 So, in this tutorial, we have learnt:
12:10 To list all the users
12:12 To fetch a book and To return a book.
12:15 To know more about the spoken tutorial project, watch the video available at the following link.
12:20 It summarizes the Spoken Tutorial Project.
12:24 If you do not have good bandwidth, you can download and watch it.
12:28 The Spoken Tutorial Project Team:
12:30 Conducts workshops using spoken tutorials.
12:32 Gives certificates to those who pass an online test.
12:36 For more details, please write to contact at spoken hyphen tutorial dot org.
12:41 Spoken Tutorial Project is a part of the "Talk to a Teacher" Project.
12:44 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
12:50 More information on this mission is available at:
12:52 http://spoken-tutorial.org/NMEICT-Intro
12:58 The Library Management System has been contributed by a leading software MNC through their Corporate Social Responsibility Programme.
13:06 They have also validated the content for this spoken tutorial.
13:10 This is Arya Ratish from IIT Bombay, signing off. Thank you for joining.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Sandhya.np14