Professional Documents
Culture Documents
PROJECT CERTIFICATE
of BCA examination and has been carried out under my direct supervision and guidance. This report or a similar report on the topic has not been submitted for any other examination and does not form a part of any other course undergone by the candidate.
Name Place
: :
ACKNOWLEDGEMENT
A formal statement of acknowledgement is hardly sufficient to express my gratitude towards the personalities who have helped me undertake this project. I hereby convey my thankfulness and obligation to all those who have rendered their valuable help, support and guidance to meet this end. I would like to thank Mr. SHIV KUMAR for spending his precious time for
completion of this project and providing their valuable comments, practical and theoretical guidance and constant encouragement that have been a source of inspiration to this entire project. I am very thankful to staff member of Library with our project at their concern. I would also like to thank all my friends who had directly or indirectly helped me in my project work.
SHASHI BALA
INDEX
TITLE PAGE---------------------------------------------------------------------ACKNOWLEDGEMENT-----------------------------------------------------HARDWARE AND SOFTWARE REQUIREMENTS------------------SHOPPING CART APPLICATION ---------------------------------------ARCHITECTURE OF THE S.C.A.-----------------------------------------ARCHITECTURE OF ONLINE SHOPPING MODULE--------------ARCHITECTURE OF THE ADMINISTRATION MODULE--------DESIGNING ONLINE DATABASE----------------------------------------BOOK DETAILS TABLE ----------------------------------------------------CATAGORY DETAILS TABLE -------------------------------------------ORDER DETAILS TABLE --------------------------------------------------TEMP DETAIL TABLE ------------------------------------------------------USER AUTH. TABLE --------------------------------------------------------USER PROFILE TABLE------------------------------------------------------MAIN SCREEN -----------------------------------------------------------------SOURCE CODE ----------------------------------------------------------------1 2 4 5 6 7 10 13 14 16 17 18 20 21 24 30
Software Requirements:
Windows XP Professional or Windows 2000 or higher Operating System. Java Notepad
The Shopping Cart application enables an end user to search a specific book in an online database, place an order for it and also purchase it online. The application also enables you to manage the data stored in a database for the online displayed books, such as adding a book, adding a book category and modifying the book information. This chapter shows how to create the Shopping Cart application, using JSP (Java Server Pages) as the server side scripting language, JavaScript for client side data validations, HTML (Hyper Text Markup Language) for data display and Oracle as the database to store the various information, such as books information, customer information, order placed information.
The shopping Cart application consists of various HTML and JSP pages such as Login.htm of Validate.jsp. Figure shows the architecture of Shopping Cart application. The login.htm page is displayed first when the end user executes the Shopping Cart application. The Login.htm page displays a login from to allow registered user to logon and a hyperlink for the unregistered users to register first a new end user clicks the New User? Register hyperlink to open the NewUser.htm page. The Sign.jsp page in the new user registration from validates the values entered by the end user and saves the information about the new user in the User_Profile tables and the user name and password in User_Auth table. The Validat.jsp page is called when the end user enters the username and password in the login form and clicks the Login button of Login.htm page. The Validate.jsp page verifies username and password are entered of no. the InvalidUser.htm page is displayed if login fails. The Admin.htm page opens if login succeeds and the end user is the administrator else the SearchCriteria.jsp page opens.
The Shopping Cart application has two modules online shopping module and administration module. The online shopping module consists of HTML and JSP pages that enables and en user to login and logout as a registered user and to shop search for a book from the online database. Figure shows architecture of the online shopping module of Shopping Cart application. The SearchCriteria.jsp page in the architecture of the online shipping module enables the end user to select criteria for searching books, such as book title and book author. It also allows the end user to enter a value in a text box to search for selected criteria.
The Search.jsp page is called on clicking the Search button of the Search.jsp page. The search.jsp page allows the end user to select books from the search result and add them to the cart. A cart is a shopping basket that stores the books selected by an end user. It also allows the end user to search for more books. The Inter_Cart.jsp page is called on clicking the Add to Cart button one the Search.jsp page. The Inter_Cart.jsp page creates the session variables and calls the Cart.jsp page. The session variables are the variables that store information about an end user for a particular session, such as user name and password.
8
The Cart.jsp page displays the data stored in the cart of an end user and allows end user to search for more books. The NewSearch.jsp page is called on clicking the Search button of the Cart.jsp page. The NewSearch.jsp page allows the end user to select books form the search results and add books to the cart. It also allows the end user to search for more books. The NewInter_cart.jsp page is called the Add to Cart button to the NewSearch.jsp page. The NewInter_Cart.jsp page creates the session variables and calles the Cart.jsp page. The session variables in the NewInter_cart stores the updated information of books selected by an end user. The Cart_quantity.jsp page is called the place Order button of Cart.jsp page.
The Cart_quantity page enables the end user to enter the number of copies of each book present in the end users cart and displays the total bill for the end user.
The Shop.jsp page is called on clicking the place Order button of the Cart_quantity.jsp page. The Shop.jsp page enables the end user to enter his credit card number and its expiry date.
The Final.jsp page is called on clicking the Submit button of Shop.jsp page. The Final.jsp page displays the order number, date of order and the total bill for the books selected by the end user.
9
All the pages of the online shipping module duisplay a Click here to Logout hyperlink for the end user to logout. The Logout.jsp page is called on clicking the logout hyperlink provided on each page. The Unauthorised.htm page is displayed when an end user tries to open some page of Shopping Cart application by simply specifying the URL (Universal Resource Locator)
10
11
The Modify_Book.jsp page is called on clicking the Modify button of the Modify.jsp page. The Modify_Book.jsp page allows the end user to make changes in the details of the selected book. The Final_Mod_Book.jsp page is called on clicking the Save Changes button of the Modify_Book.jsp page. The Final_Mod_Book.jsp page displays a message starting that the book details have been successfully modified and contains
hyperlinks for going to Admin .htm page, Modify.jsp page of Logout.htm page. The Insert_Category.jsp page is called the Insert Book Category hyperlink of the Admin.htm page. The Insert_Category.jsp page displays the available book categories in a combo box component and allows the end user enter the name of the new book category to be added. The Add Category.jsp page is called on clicking the Add button of the Insert_Category page. The AddCategory.jsp page displays a message stating that the book category has been successfully added and contains three hyperlinks for going to Admin.htm page, Insert_Category.jsp page or Logout.htm page. The Update_category.jsp page is called on clicking the Modify Book Category hyperlink of the Admn.htm page. The Update_category.jsp page displays the available book categories in a combo boxs and allows the end user to select the name of the category to be modified from the combo box options. The name of the selected category is displayed in textbox and the end user is allowed to make changes in the category name.
12
The Modify.Category.jsp page is displayed on clicking the Modify button of the Modify.jsp page. The ModifyCategory.jsp page displays a message stating that the book category has been successfully modified and contains three hyperlinks for going to Admin.htm page, Update_Category.jsp page of Logout.htm page. All the pages of the administration module display a hyperlink to allow the end user to logout. The Logout.jsp page is called on clicking the logout hyperlink provided on each page.
13
14
The Book_Details table stores information about the books available in the shopping cart Listing shows how to create the Book_Details table:
Creating the book_Details Table Create table Boook_Details { BookID number(5) primary key, CategoryID number(5) Title varchar2(50), Author carchar2(30)
15
Publisher varchar2(30), Edition varchar2(5), Price number(7 ,2) Quantity number(3) Description varchar2(100), Constraint cat_fk foreign key(categoryid) References category_details (categoryid)
);
16
The Category_Detaisl table contains two fields, such as category ID and Category_Name to store information about book categories. Tables lists the structure of the Ctegory_Details table:
Listing shows how to create the Cagtegory_Details table Creating the Category_Details Table Create table Category_Details ( categoryID number(5) primary key, CategoryName varchar2(30) );
17
Listing shows how to create the Order_Details table: Creating the Order_Details Talbe Create table order_Details ( OrderID number(5) BookID number(5) Quantity number(3) Constraint order_fk foreign key(ordered) References order_table (ordered), Constraint book_fk foreign key (bookid) References book_details(bookid)
18
);
Listing shows how to create the Temp_Detail table: Creating the Temp_Detail Table Create table Temp_Detail
19
( BookID number(5), CategoryID number (5), Title varcher2(50) Author varchar2(30), Publisher varchar2(5), Edition varchar2(5), Price number(7,2) Quantity number(3), Description varchar2(100) );
20
Listing shows how to create the User_Auth table: Creating the User_Auth Table Creating the User_Auth ( UserName varchar2(30), Password varchar2(15), Constraint uname_fk foreign key (username) References user_profile (username), );
21
The User_Profile table contains various fields, such as FirstName to store information about all registered users. Table lists the structure of the User_Profile table: Structure of the User_Profile Table Field Name UserName Password FirstName MiddleName LastName Address1 Address2 City State PinCode Email Phone Data Type Varchar2(30), primary key Varchar2(15), not null Varchar2(10), not null Varchar2(10) Varchar2(10), not null Varchar2(40), not null Varchar2(40) Varchar2(20), not null Varchar2(20), not null Varchar2(10), not null Varchar2(25), not null Varchar(12), not null
Listing shows how create the User_profile table: Creating the User_Profile Table
CREATE TABLE User_Profile ( Username varchar2 (30) primary key, Password Varchar2 (15) NOT NULL,
22
FirstName Varchar2 (10) NOT NULL, MiddleName Varchar2 (10), LastName Varchar2 (10) NOT NULL, Address1 Varchar2 (40) NOT NULL, Address2 Varchar2 (40), City Varchar2 (20) NOT NULL, State Varchar2 (20) NOT NULL, PinCode Varchar2 (10), Email Varchar2 (25) NOT NULL, Phone varchar (12) )
23
24
25
26
27
28
29
30
31
<html> <head> <title>Login</title> </head> <body bgcolor="#CCFFFF"> <CENTER> <H1> <u>Online Shopping Cart</u> </H1> </CENTER> <SCRIPT language="JavaScript"> function validate() { if(document.frm.UserName.value==""||document.frm.Password.value=="") { alert("UserName or Password cannot be blank!!"); return; } document.frm.action="Validate.jsp"; document.frm.submit(); } </SCRIPT> <form name = frm method="POST"> <p align="center"><font size="5"><b>Login Form</b></font></p> <TABLE ALIGN="center" height="57"> <TR> <TD > <b>UserName:</b> </TD> <TD > <input type="text" name="UserName" size="20" tabindex="1"> </TD> </TR> <TR> <TD > <b>Password:</b> </TD> <TD > <input type="password" name="Password" size="20" tabindex="2"> </TD> <TR align="center"> <TD colspan=2> <input type="button" value=" Login " name="B1" onclick="validate();" tabindex="3"> </TD> </TR> <TR > <TD ><font size="4">New User?</font></TD> <TD><a href="NewUser.htm"><font size="4">Register</font></a></TD> </TR> </TABLE> </form> </body>
32
</HTML>
33
{ alert("City cannot be blank"); return; } if( document.form1.State.value=="Select State") { alert("You must select a state"); return; } if( document.form1.PinCode.value=="") { alert("PinCode cannot be blank"); return; } if( document.form1.Email.value=="") { alert("Email ID cannot be blank"); return; } if( document.form1.Phone.value=="") { alert("Phone Number cannot be blank"); return; } document.forms[0].action="Sign.jsp"; document.forms[0].submit(); } </SCRIPT> <p align="center"> <b><font size="5"> New User Registration</font></b> </p> <p align="left"> <b><font color="#FF0000">( Field marked * are necessary)</font> &nbs p; & nbsp;</b> </p> <div align="left"> <table border="0" width="100%"> <tr> <td width="23%"><b>User *:</b></td> <td width="77%"> <b> <input type="text" name="UserName" size="20" tabindex="1"> </b> </td> </tr> <tr>
34
<td width="23%"> <b> Password*:</b></td> <td width="77%"><b><input type="password" name="Password" size="20" tabindex="2"> </b> </td> </tr> <tr> <td width="23%"> <b> Confirm Password*:</b> </td> <td width="77%"><b><input type="password" name="Password2" size="20" tabindex="3"> </b> </td> </tr> <tr> <td width="23%"> <b> First Name*:</b></td> <td width="77%"> <b><input type="text" name="FirstName" size="20" tabindex="4"> </b> </td> </tr> <tr> <td width="23%"> <b> Middle Name:</b></td> <td width="77%"> <b> <input type="text" name="MiddleName" size="20" tabindex="5"> </b> </td> </tr> <tr> <td width="23%"> <b> Last Name*:</b></td> <td width="77%"> <b><input type="text" name="LastName" size="20" tabindex="6"> </b> </td> </tr> </table> </div> <div align="center"> <center> <table border="0" width="100%" height="201"> <tr> <td width="23%" height="25"><b>Address1*: </b></td>
35
<td width="77%" height="25"><b><input type="text" name="Address1" size="43" tabindex="7"> </b> </td> </tr> <tr> <td width="23%" height="25"><b>Address2: </b></td> <td width="77%" height="25"><b><input type="text" name="Address2" size="43" tabindex="8"> </b> </td> </tr> <tr> <td width="23%" height="25"><b>City*: </b></td> <td width="77%" height="25"><b><input type="text" name="City" size="20" tabindex="9"> </b> </td> </tr> <tr> <td width="23%" height="25"><b>State*:</b></td> <td width="77%" height="25"><b><select size="1" name="State" tabindex="10"> <option selected value="Select State">Select State</option> <option>Assam</option> <option>Arunachal Pradesh</option> <option>Haryana</option> <option>Maharashtra</option> <option>Rajasthan</option> <option>Uttar pradesh</option> </select> </b> </td> </tr> <tr> <td width="23%" height="25"><b>Pin Code*: </b></td> <td width="77%" height="25"><b><input type="text" name="PinCode" size="20" tabindex="11"> </b> </td> </tr> <tr> <td width="23%" height="25"><b>Email ID*:</b></td> <td width="77%" height="25"><b><input type="text" name="Email" size="20" tabindex="12"> </b> </td> </tr> <tr> <td width="23%" height="25"><b>Phone Number*:</b></td> <td width="77%" height="25"><b><input type="text" name="Phone" size="20" tabindex="13"> </b> </td> </tr> <tr> <td width="23%" height="1"></td> <td width="77%" height="1"> </td> </tr> <tr> <td width="23%" height="21"></td> <td width="77%" height="21"> <b> <input type="submit" value="Submit" name="B1" onclick="validate();" tabindex="13"> </b> </td>
36
37
38
String State=request.getParameter("State"); String PinCode=request.getParameter("PinCode"); String Email=request.getParameter("Email"); String Phone=request.getParameter("Phone"); int flag=0; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn =DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); PreparedStatement stat= conn.prepareStatement("SELECT * FROM user_profile where username=?" ); stat.setString(1,UserName); rs = stat.executeQuery(); out.println("query executed"); if(rs.next()) { flag=1; %> <SCRIPT language="JavaScript"> alert("User name already exists"); location.href="NewUser.htm"; </SCRIPT> <% } else { flag=0; // conn.close(); } } catch(Exception E) { out.println("Error "+E); } if(flag == 0) { try { PreparedStatement stat1=conn.prepareStatement("INSERT INTO user_auth values(?,?)"); stat1.setString(1,UserName); stat1.setString(2,Password); PreparedStatement stat=conn.prepareStatement("INSERT INTO user_profile values(?,?,?,?,?,?,?,?,?,?,?,?)"); stat.setString(1,UserName); stat.setString(2,Password); stat.setString(3,FirstName);
39
stat.setString(4,MiddleName); stat.setString(5,LastName); stat.setString(6,Address1); stat.setString(7,Address2); stat.setString(8,City); stat.setString(9,State); stat.setString(10,PinCode); stat.setString(11,Email); stat.setString(12,Phone); stat.executeUpdate(); stat1.executeUpdate(); flag=0; response.sendRedirect("Login.htm"); } catch(Exception E) { out.println("Error inserting value"+E); } finally { rs.close(); conn.close(); } } %> </body> </html>
40
stat.setString(2,strPass); rs = stat.executeQuery(); if(rs.next()) { String str1,str2; str1=rs.getString(1); str2=rs.getString(2); out.println(str1+str2); session.putValue("user",strName); if(str1.equals("Administrator")) { response.sendRedirect("Admin.htm"); } else { out.println("Logged IN"); response.sendRedirect("SearchCriteria.jsp"); } } else { response.sendRedirect("InvalidUser.htm"); } } catch(Exception E) { out.println("Error "+E); } finally { rs.close(); conn.close(); } %> </body> </html>
41
<H1> <u>Online Shopping Cart</u> </H1> </CENTER> <SCRIPT language="JavaScript"> function startSearch() { if(document.frm.R1[1].checked) { if(document.frm.BookTitle.value=="") { alert("You must enter a book title"); return; } } if(document.frm.R1[2].checked) { if(document.frm.BookAuthor.value=="") { alert("You must enter an author name"); return; } } if(document.frm.R1[3].checked) { if(document.frm.BookPublisher.value=="") { alert("You must enter a publisher name"); return; } } document.frm.action="search.jsp"; document.frm.submit(); } </SCRIPT> <%@ page errorPage="errorpage.jsp" import="java.net.*" %> <%@ page import="java.io.*" %> <%@ page import="java.sql.*" %> <% Connection con = null; PreparedStatement stat = null; ResultSet rs = null; int ctr=0, flag=0; try {
42
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); stat = con.prepareStatement("select * from category_details"); rs=stat.executeQuery(); %> <form name ="frm" method="POST"> <center><font size="5">Search Books</font></p></center> <BR><BR> <table border="0" width="100%" height="196"> <tr> <td width="17%" align="right" height="25"><input type="radio" value="Category" checked name="R1"></td> <td width="32%" height="25">Search by Category</td> <td width="51%" height="25"> <select size="1" name="BookCategory"> <option selected value="Select">Select Category</option> <% while(rs.next()) { String category=rs.getString(2);%> <option value="<%=category%>"><%=category%></option> <%}%> </select> </td> </tr> <tr> <td width="17%" align="right" height="25"><input type="radio" name="R1" value="Title"></td> <td width="32%" height="25">Search by Book Title</td> <td width="51%" height="25"><input type="text" name="BookTitle" size="25"></td> </tr> <tr> <td width="17%" align="right" height="25"><input type="radio" name="R1" value="Author"></td> <td width="32%" height="25">Search by Book Author</td> <td width="51%" height="25"><input type="text" name="BookAuthor" size="25"></td> </tr> <tr> <td width="17%" align="right" height="25"><input type="radio" name="R1" value="Publisher"></td> <td width="32%" height="25">Search by Book Publisher</td> <td width="51%" height="25"><input type="text" name="BookPublisher" size="25"></td> </tr>
43
<tr> </tr> <tr> <td width="17%" align="right" height="21"></td> <td width="32%" height="21"> <input type="button" value=" Search " name="Search" onClick="startSearch();"></td> <td width="51%" height="21"><a href="Logout.jsp">Click here to logout</a></td> </tr> </table> </form> <% } catch(Exception e) { out.print("Error = " + e + "<HR>"); } finally { rs.close(); con.close(); } %> </body> </html>
44
int chk_ctr=0; String str_colvar=null; String tab_var=""; String user_src=(String)session.getValue("user"); System.out.println("0"); if (user_src!=null) { String query=null; Connection conn; conn=null; ResultSet rs; rs=null; if(request.getParameter("R1").equals("Title")) { str_searchvar=request.getParameter("BookTitle"); str_colvar="TITLE"; } if(request.getParameter("R1").equals("Category")) { chk_ctr=1; str_searchvar=request.getParameter("BookCategory"); str_colvar="Categoryname"; } if(request.getParameter("R1").equals("Publisher")) { str_searchvar=request.getParameter("BookPublisher"); str_colvar="Publisher"; } if(request.getParameter("R1").equals("Author")) { str_searchvar=request.getParameter("BookAuthor"); str_colvar="Author"; } if (request.getParameter("R2")==null) { tab_var="BOOK_DETAILS"; } else { // to get the name of the table in which the search to be done------if (request.getParameter("R2").equals("A")) { tab_var="TEMP_DETAIL"; } else { tab_var="BOOK_DETAILS"; } }
45
System.out.println(str_searchvar); query = "select a.* from "+tab_var+" a, category_details b where a."+str_colvar+" = ? and a.CATEGORYID = b.CATEGORYID"; System.out.println("1"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn =DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); int ctr=0; System.out.println("2"); PreparedStatement stm = conn.prepareStatement(query); stm.setString(1,str_searchvar); rs = stm.executeQuery(); %> <form name="cart" action="Inter_Cart.jsp" method="POST"> <table border=1> <tr> <td>S.No</td> <td>Select</td> <td>Book Name</td> <td>Author Name</td> <td>Publisher</td> <td>Edition</td> <td>Price (in Rs.)</td> <td>Quantity Available(Nos.)</td> <td>Description</td> </tr> <% while(rs.next()) { System.out.println("inside while"); ctr=ctr+1; out.println("<tr><td>"+ctr+"</td>"); int int_BOOKID=0; int_BOOKID=rs.getInt(1); System.out.println(int_BOOKID); out.println("<td><input type=checkbox name=chk"+ctr+" value="+int_BOOKID+">"); int int_CATEGORYID=rs.getInt(2); String str_TITLE=rs.getString(3); out.println("<td>"); out.println(str_TITLE); out.println("</td>"); String str_AUTHOR=rs.getString(4); out.println("<td>"); out.println(str_AUTHOR); out.println("</td>");
46
String str_PUBLISHER=rs.getString(5); out.println("<td>"); out.println(str_PUBLISHER); out.println("</td>"); String str_EDITION=rs.getString(6); out.println("<td>"); out.println(str_EDITION); out.println("</td>"); int int_PRICE=rs.getInt(7); out.println("<td>"); out.println(int_PRICE); out.println("</td>"); int int_QUANTITY=rs.getInt(8); out.println("<td>"); out.println(int_QUANTITY); out.println("</td>"); String str_DESCRIPTION=rs.getString(9); out.println("<td>"); out.println(str_DESCRIPTION); out.println("</td></tr>"); String ins_query ="INSERT INTO temp_detail VALUES (?,?,?,?,?,?,?,?,?)"; PreparedStatement stat_ins= conn.prepareStatement(ins_query); stat_ins.setInt(1,int_BOOKID); stat_ins.setInt(2,int_CATEGORYID); stat_ins.setString(3,str_TITLE); stat_ins.setString(4,str_AUTHOR); stat_ins.setString(5,str_PUBLISHER); stat_ins.setString(6,str_EDITION); stat_ins.setInt(7,int_PRICE); stat_ins.setInt(8,int_QUANTITY); stat_ins.setString(9,str_DESCRIPTION); int x = stat_ins.executeUpdate(); System.out.println(x); } String str_ctr=String.valueOf(ctr); session.putValue("ctr_val",str_ctr); %> </table>
47
Add to Cart
" name="Add">
48
49
</CENTER> <BR> <a href="Logout.jsp" ><font size="4" >Click here to Logout</font></a> <%@ page errorPage="errorpage.jsp" language="java" import="java.sql.*" %> <% int i; String user_src=null; user_src=(String)session.getValue("user"); if (user_src!=null) { int counter=0; counter=Integer.parseInt((String)session.getValue("TotalSel")); int[] bookid=new int[counter]; Connection conn; conn=null; ResultSet rs; rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn =DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); PreparedStatement stat=null; int ctr=0,bookprice=0; for(i=1;i<=counter;i++) { if((String)session.getValue("chk_var"+i)!=null) { bookid[i1]=Integer.parseInt((String)session.getValue("chk_var"+i)); } } session.putValue("BookArr",bookid); %> <h3>Your Cart Details are as follows:</h3> <form name="shop" action="Cart_Quantity.jsp"> <table border=1> <tr> <td>S.No</td> <td>Book Name</td> <td>Price (in Rs.)</td> </tr> <% int price=0; for (int j=1;j<=counter;j++) { out.println("<tr><td>"+j); String query="select title, price from book_details where bookid=?"; stat= conn.prepareStatement(query);
50
stat.setInt(1,bookid[j-1]); rs = stat.executeQuery(); while (rs.next()) { out.println("<td>"); out.println(rs.getString(1)); out.println("<td>"); price=rs.getInt(2); out.println(price); } rs.close(); bookprice=bookprice+price; session.putValue("bPrice",String.valueOf(bookprice)); out.println("</tr>"); } ResultSet rscombo=null; String query1="select * from category_details"; PreparedStatement stat_combo = conn.prepareStatement(query1); rscombo=stat_combo.executeQuery();%> <tr> <td colspan=3>Total Cart Amount(in Rs.)= <%=bookprice%><td> </tr> </table> <br> <input type=submit value="Place Order"> </form> <br><hr><h3>Search More</h3> <form name="search" action="NewSearch.jsp" method="POST"> <table border=1> <tr> <td><input type="radio" value="Category" checked name="R1"></td> <td>Search based on Category</td> <td> <select size="1" name="BookCategory"> <option selected value="Select">Select Category</option> <% while(rscombo.next()) { String category=rscombo.getString(2); %> <option value="<%=category%>"><%=category%></option> <%}%> </select> </td> </tr> <tr>
51
<td><input type="radio" name="R1" value="Title"></td> <td>Search by Book Title</td> <td><input type="text" name="BookTitle" size="25"></td> </tr> <tr> <td><input type="radio" name="R1" value="Author"></td> <td>Search by Book Author</td> <td><input type="text" name="BookAuthor" size="25"></td> </tr> <tr> <td><input type="radio" name="R1" value="Publisher"></td> <td>Search by Book Publisher</td> <td><input type="text" name="BookPublisher" size="25"></td> </tr> <tr> <td><input type="radio" name="R2" value="A">Advanced Search</td> <td><input type="radio" name="R2" value="N" checked>New Search</td> <td><input type=submit value="Search"></td> </tr> </table> </form> <%} else { response.sendRedirect("Unauthorised.htm"); } %> </body> </html>
52
if (user_src!=null) { String str_searchvar=null; String str_colvar=null; String query=""; String tab_var=""; int total_sel=Integer.parseInt((String)session.getValue("TotalSel")); int[] old_bookid=new int[total_sel]; Connection conn; conn=null; ResultSet rs; rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn =DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); PreparedStatement stat=null,stat_ins=null,stat_del=null; for (int i=1;i<=total_sel;i++) { old_bookid[i-1]=Integer.parseInt((String)session.getValue("chk_var"+i)); }%> <h3>Your Cart Details are as follows:</h3> <form name="shop" action="Cart_quantity.jsp"> <table border=1> <tr> <td>S.No</td> <td>Book Name</td> <td>Price (in Rs.)</td> </tr> <% int price=0; int bookprice=0; for (int j=0;j<total_sel;j++) { out.println("<tr><td>"+j+1); query="select title, price from book_details where bookid=?"; stat= conn.prepareStatement(query); stat.setInt(1,old_bookid[j]); rs = stat.executeQuery(); while (rs.next()) { out.println("<td>"); out.println(rs.getString(1)); out.println("<td>"); price=rs.getInt(2); out.println(price); }
53
rs.close(); bookprice=bookprice+price; out.println("</tr>"); }%> <tr> <td colspan=3>Total Cart Amount(in Rs.)= <%=bookprice%> <td></tr> </table> <br> <input type=submit value="Place Order"> </form> <% String test_src=null; int chk_ctr=0; if(request.getParameter("R1").equals("Title")) { str_searchvar=request.getParameter("BookTitle"); str_colvar="Title"; } if(request.getParameter("R1").equals("Category")) { chk_ctr=1; str_searchvar=request.getParameter("BookCategory"); str_colvar="Categoryname"; } if(request.getParameter("R1").equals("Publisher")) { str_searchvar=request.getParameter("BookPublisher"); str_colvar="Publisher"; } if(request.getParameter("R1").equals("Author")) { str_searchvar=request.getParameter("BookAuthor"); str_colvar="Author"; } String ss = request.getParameter("R2"); if (request.getParameter("R2")==null) { tab_var="book_details"; } else { // to get the name of the table in which the search to be done------if (request.getParameter("R2").equals("A"))
54
{ tab_var="temp_detail"; } else { tab_var="book_details"; } } //-------- whether search is by category or other criteria----------if (chk_ctr==0) { query="select a.* from "+tab_var+" a, category_details b where a."+str_colvar+" = ? and a.CATEGORYID = b.CATEGORYID"; } else { query="SELECT a.*,b.categoryname FROM "+tab_var+" a,CATEGORY_DETAILS b where b."+str_colvar+"=? and a.categoryid=b.categoryid"; } try { stat=conn.prepareStatement(query); stat.setString(1,str_searchvar); rs = stat.executeQuery(); int ctr=0;%> <h3>Search Results are as follows:</h3> <form name="cart" action="NewInter_cart.jsp" method="POST"> <table border=1> <tr> <td>S.No</td> <td>Select</td> <td>Book Name</td> <td>Author Name</td> <td>Publisher</td> <td>Edition</td> <td>Price (in Rs.)</td> <td>Quantity Available(Nos.)</td> <td>Description</td> </tr> <% String delete_query="Delete from TEMP_DETAIL";
55
stat_del= conn.prepareStatement(delete_query); String ins_query=null; int int_BOOKID,int_CATEGORYID,int_PRICE,int_QUANTITY; String str_TITLE,str_AUTHOR,str_PUBLISHER,str_EDITION,str_DESCRIPTION; int rs_del=stat_del.executeUpdate(); while(rs.next()) { ctr=ctr+1; out.println("<tr><td>"+ctr); int_BOOKID=rs.getInt(1); out.println("<td><input type=checkbox name=chk"+ctr+" value="+int_BOOKID+">"); int_CATEGORYID=rs.getInt(2); str_TITLE=rs.getString(3); out.println("<td>"); out.println(str_TITLE); str_AUTHOR=rs.getString(4); out.println("<td>"); out.println(str_AUTHOR);
str_PUBLISHER=rs.getString(5); out.println("<td>"); out.println(str_PUBLISHER); str_EDITION=rs.getString(6); out.println("<td>"); out.println(str_EDITION); int_PRICE=rs.getInt(7); out.println("<td>"); out.println(int_PRICE); int_QUANTITY=rs.getInt(8); out.println("<td>"); out.println(int_QUANTITY); str_DESCRIPTION=rs.getString(9); out.println("<td>"); out.println(str_DESCRIPTION); out.println("</tr>");
56
ins_query="INSERT INTO TEMP_DETAIL VALUES(?,?,?,?,?,?,?,?,?)"; stat_ins=conn.prepareStatement(ins_query); stat_ins.setInt(1,int_BOOKID); stat_ins.setInt(2,int_CATEGORYID); stat_ins.setString(3,str_TITLE); stat_ins.setString(4,str_AUTHOR); stat_ins.setString(5,str_PUBLISHER); stat_ins.setString(6,str_EDITION); stat_ins.setInt(7,int_PRICE); stat_ins.setInt(8,int_QUANTITY); stat_ins.setString(9,str_DESCRIPTION); int rs_ins=stat_ins.executeUpdate(); } String str_ctr=String.valueOf(ctr); session.putValue("ctr_val",str_ctr); %> </table> <input type="submit" value=" </form> <% Add to Cart " name="Add">
ResultSet rscombo=null; String query1="select * from category_details"; PreparedStatement stat_combo = conn.prepareStatement(query1); rscombo=stat_combo.executeQuery();%> <br><h3>Search Results are as follows:</h3> <form name="newsrc" action="NewSearch.jsp" method="POST"> <table border=1> <tr> <td><input type="radio" value="Category" checked name="R1"></td> <td>Search based on Category</td> <td> <select size="1" name="BookCategory"> <option selected value="Select">Select Category</option> <% while(rscombo.next()) { String category=rscombo.getString(2); %> <option value="<%=category%>"><%=category%></option> <%}%>
57
</select> </td> </tr> <tr> <td><input type="radio" name="R1" value="Title"></td> <td>Search by Book Title</td> <td><input type="text" name="BookTitle" size="25"></td> </tr> <tr> <td><input type="radio" name="R1" value="Author"></td> <td>Search by Book Author</td> <td><input type="text" name="BookAuthor" size="25"></td> </tr> <tr> <td><input type="radio" name="R1" value="Publisher"></td> <td>Search by Book Publisher</td> <td><input type="text" name="BookPublisher" size="25"></td> </tr> <tr> <td><input type="radio" name="R2" value="A">Advanced Search</td> <td><input type="radio" name="R2" value="N" checked>New Search</td> <td><input type=submit value="Search"></td> </tr> </table> </form> <%} catch(Exception E) { out.println("Error "+E); } finally{conn.close();} } else { response.sendRedirect("Unauthorised.htm"); } %> </body> </html>
58
int i; String bookid=null; String user_src=null; user_src=(String)session.getValue("user"); if (user_src!=null) { int counter=0; int total_sel=Integer.parseInt((String)session.getValue("TotalSel")); counter=Integer.parseInt((String)session.getValue("ctr_val")); int ctr=total_sel; for(i=1;i<=counter;i++) { if(request.getParameter("chk"+i)!=null) { bookid=request.getParameter("chk"+i); ctr=ctr+1; session.putValue("chk_var"+ctr,bookid); } } session.putValue("TotalSel",String.valueOf(ctr)); response.sendRedirect("Cart.jsp"); } else { out.println("Unauthorised Shopping is not allowed"); } %>
59
{ int counter=0; counter=Integer.parseInt((String)session.getValue("TotalSel"));%> <script language="Javascript"> function check_sum() { var cost=0; x_avlqty=new Array(<%=counter%>); y_orderqty=new Array(<%=counter%>); z_price=new Array(<%=counter%>); for (var i=0;i<<%=counter%>;i++) { z_price[i]=(document.shop.elements[i*4].value); x_avlqty[i]=document.shop.elements[i*4+1].value; y_orderqty[i]=document.shop.elements[i*4+2].value; if(parseInt(y_orderqty[i])<0) { alert("Book quantity cannot be Negative"); return false; } if (parseInt(x_avlqty[i])<parseInt(y_orderqty[i])) { alert("Order Quantity Cannot be greater than available quantity"); return false; } else { document.shop.elements[i*4+3].value=((parseInt(y_orderqty[i]))*(parseInt(z_price[i]))); cost=cost+parseInt(document.shop.elements[i*4+3].value); } } document.shop.tot_val.value=cost; } </script> <% int[] bookid=new int[counter]; Connection conn; conn=null; ResultSet rs; rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn =DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); PreparedStatement stat=null; int ctr=0,bookprice=0; for(i=1;i<=counter;i++) {
60
if((String)session.getValue("chk_var"+i)!=null) { bookid[i1]=Integer.parseInt((String)session.getValue("chk_var"+i)); } } session.putValue("BookArr",bookid); %> <h3>Your Cart Details are as follows:</h3> <form name="shop" action="Shop.jsp" method="POST"> <table border=1> <tr> <td>S.No</td> <td>Book Name</td> <td>Price per unit (in Rs.)</td> <td>Quantity Available</td> <td>Quantity Purchased</td> <td>Amount</td> </tr> <% int price=0; int qty_avbl=0; for (int j=1;j<=counter;j++) { out.println("<tr><td>"+j); out.println("</td>"); String query="select title, price,quantity from book_details where bookid=?"; stat= conn.prepareStatement(query); stat.setInt(1,bookid[j-1]); rs = stat.executeQuery(); while (rs.next()) { out.println("<td>"); out.println(rs.getString(1));out.println("</td>"); price=rs.getInt(2);%> <td><input type="hidden" name="bk_price<%=j%>" value=< %=price%></td> <%out.println(price); qty_avbl=rs.getInt(3);%> <td><input type=hidden name="qty_avl<%=j%>" value=< %=qty_avbl%>><%=qty_avbl%></td> <td><input type=text name="qty<%=j%>" value="0" onChange="return check_sum();"></td> <td><input type=text name="cal_amt<%=j%>"></td> <% }%> </tr>
61
<% rs.close(); bookprice=bookprice+price; session.putValue("bPrice",String.valueOf(bookprice)); out.println("</tr>"); }%> <tr><td><td><td><td><td>Total Amount(in Rs.)<td><input type="text" name="tot_val" value="0"></td></tr> </table> <br> <input type=submit value="Place Order"> </form> <br><hr> <%} else { response.sendRedirect("Unauthorised.htm"); } %> </body> </html>
62
var day = r.Day.value; if(creditcard.length!=16) { alert("Invalid Credit Card Number"); r.Card.focus(); return; } //----------------------------------------------------------------------if(day=="Select Day") { alert("Please select the day"); r.Day.focus(); return; } //----------------------------------------------------------------------if(month=="Select Month") { alert("Please select the month"); r.Month.focus(); return; } //----------------------------------------------------------------------if(year.length==0) { alert("Please enter the year"); r.Year.focus(); } else if (year.length!=4) { alert("Please enter the year in YYYY format"); r.Year.focus(); } //----------------------------------------------------------------------if (( month == "3" || month == "5" || month == "8" || month == "10") && (day == "31")) { alert("Please enter a valid date"); r.Day.focus(); } if ((month == "1") && (day == "30" || day == "31")) { alert("Please enter a valid date"); r.Day.focus(); } //------- To check that card date is not less than current date---------var vr_day; var vr_month; var vr_year; var d=new Date();
63
vr_year=d.getFullYear(); vr_month=d.getMonth(); vr_day=d.getDate(); if(parseInt(vr_year)>parseInt(document.form1.Year.value)) { alert("Year cannot be less than Current Year"); return false; } else if(parseInt(vr_year)==parseInt(document.form1.Year.value)) { if(parseInt(vr_month)>parseInt(document.form1.Month.value)) { alert("Month cannot be less than Current Month"); return false; } else if(parseInt(vr_month)==parseInt(document.form1.Month.value)) { if(parseInt(vr_day)>parseInt(document.form1.Day.value)) { alert("Day cannot be less than current Day"); return false; } } } //-----------------------------------------------------------------------document.form1.submit(); document.forms[0].action="Final.jsp"; } </script> <% int counter=0; counter=Integer.parseInt((String)session.getValue("TotalSel")); String query=""; int[] bookid=new int[counter]; int[] bk_price=new int[counter]; int[] bk_quantity=new int[counter]; Connection conn; conn=null; ResultSet rs; rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn =DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); PreparedStatement stat=null; int ctr=0,bookprice=0; int i=1; while(i<=counter) {
64
if((String)session.getValue("chk_var"+i)!=null) { bookid[i1]=Integer.parseInt((String)session.getValue("chk_var"+i)); query="SELECT PRICE FROM BOOK_DETAILS WHERE BOOKID=?"; stat=conn.prepareStatement(query); stat.setInt(1,bookid[i-1]); rs=stat.executeQuery(); if(rs.next()) { bk_price[i-1]=rs.getInt(1); } else { bk_price[i-1]=0; } } if(request.getParameter("qty"+i)!=null) { bk_quantity[i1]=Integer.parseInt(request.getParameter("qty"+i)); String sess_var=String.valueOf(bk_quantity[i-1]); session.putValue(sess_var,String.valueOf(bk_quantity[i-1])); } bookprice=bookprice+(bk_price[i-1]*bk_quantity[i-1]); i++; } session.putValue("bPrice",String.valueOf(bookprice)); %> <form method="POST" action="Final.jsp" name="form1"> <table width="70%"> <tr> <td colspan=4 ><b>Total Amount (in Rs.) is : <%=bookprice%></b></td></tr> <tr> </tr> <tr> <td><font size="3"><b>Credit Card Number: </b></font></td> <td colspan=3> <input type="text" name="Card" size="39" maxlength="16" tab="1"></td> </tr> <tr> <td><font size="3"><b>Expiry Date : </b></font></td> <td>
65
<select size="1" name="Day"> <option value="Select Day">Select Day</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> </td> <td> <select size="1" name="Month"> <option value="Select Month">Select Month</option> <option value="0">January</option> <option value="1">February</option> <option value="2">March</option> <option value="3">April</option> <option value="4">May</option> <option value="5">June</option> <option value="6">July</option> <option value="7">August</option> <option value="8">September</option> <option value="9">October</option> <option value="10">November</option> <option value="11">December</option> </select>
66
</td> <td> <font size="3"><input type="text" name="Year" size="11"></font> </td> </tr> </table> </font><input type="button" value="Submit" name="B1" onClick="validate();" > </form> <% } else { response.sendRedirect("Unauthorised.htm"); }%> </body> </html>
67
conn=null; ResultSet rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn =DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); PreparedStatement stat1=null,stat_sel=null,stat_ins=null; OrderID=(int)(10000*Math.random()+1); price=Integer.parseInt((String)session.getValue("bPrice")); int counter=0; counter=Integer.parseInt((String)session.getValue("TotalSel")); int[] bookid=new int[counter]; int[] bk_quantity=new int[counter]; int org_bkqty=0; int i=0; String ins_query=""; String sel_qtyQuery=""; String ins_qty=""; for(i=1;i<=counter;i++) { ResultSet rs_sql=null; if((String)session.getValue("chk_var"+i)!=null) { bookid[i1]=Integer.parseInt((String)session.getValue("chk_var"+i)); } if((String)session.getValue("bookqty"+i)!=null) { bk_quantity[i1]=Integer.parseInt((String)session.getValue("bookqty"+i)); } ins_query="INSERT INTO ORDER_DETAILS VALUES(?,?,?)"; stat1=conn.prepareStatement(ins_query); stat1.setInt(1,OrderID); stat1.setInt(2,bookid[i-1]); stat1.setInt(3,bk_quantity[i-1]); int rs_int=0; rs_int=stat1.executeUpdate(); sel_qtyQuery="SELECT QUANTITY FROM BOOK_DETAILS WHERE BOOKID = ?";
stat_sel = conn.prepareStatement(sel_qtyQuery);
68
stat_sel.setInt(1,bookid[i-1]); rs_sql=stat_sel.executeQuery(); if(rs_sql.next()) { org_bkqty=rs_sql.getInt(1); } rs_sql.close(); String ns_qty="UPDATE BOOK_DETAILS SET QUANTITY=? WHERE BOOKID=?"; stat_ins=conn.prepareStatement(ns_qty); stat_ins.setInt(1,org_bkqty-bk_quantity[i-1]); stat_ins.setInt(2,bookid[i-1]); rs_int=stat_ins.executeUpdate(); } }catch(Exception e){}
%> <form name="newsrc" method="POST"> <BR><font size="3"><b> Your order has been successfully placed. <BR><BR>Order Number is : <%=OrderID%> <BR><BR>Total Amount is : <%=price%> <BR><BR>Date of Order is: <% out.println((new java.util.Date()).toLocaleString()); %> <BR><BR> Your Order will be delivered within next 48 working hours <% String card_no=request.getParameter("Card"); Connection con= null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con =DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); java.util.Date now = new java.util.Date(); DateFormat df1 = DateFormat.getDateInstance(DateFormat.SHORT); String s1 = df1.format(now); try { String str = "insert into order_table values(?,?,?,?)"; PreparedStatement stat= con.prepareStatement(str); stat.setInt(1,OrderID);
69
stat.setString(2,user_src); stat.setInt(3,price); stat.setString(4,s1); int x = stat.executeUpdate(); }catch(Exception e){out.println(e); } } else { response.sendRedirect("Unauthorised.htm"); } %>
</body> </html>
70
<TH><a href="Modify.jsp">Modify Book Details</a></TH> </TR> <TR> <TH>2</TH> <TH align = "left">Category</TH> <TH><a href="Insert_Category.jsp">Insert Book Category</a></TH> <TH><a href="Update_Category.jsp">Modify Book Category</a></TH> </TR> </BODY> </HTML>
71
{ alert("Please Enter Edition"); return; } if(document.addbook.price.value=="") { alert("Please Enter Price (in Rs.)"); return; } if(document.addbook.qty.value=="") { alert("Please Enter Quantity"); return; } if(document.addbook.desc.value=="") { alert("Please Enter Description"); return; } if(isNaN(document.addbook.price.value)) { alert("Please Enter a numeric value for Price (in Rs.)"); ctr=1; } if(isNaN(document.addbook.qty.value)) { alert("Please Enter a numeric value for Quantity"); ctr=1; } if(ctr==0) { document.forms[0].action="AddBook.jsp"; document.forms[0].submit(); } else { return true; }; } </SCRIPT> <%@ page errorPage="errorpage.jsp" import="java.net.*" %> <%@ page import="java.io.*" %> <%@ page import="java.sql.*" %> <% Connection con = null; //Statement stat = null; PreparedStatement stat = null; //Statement stat1 = null;
72
PreparedStatement stat1 = null; ResultSet rs = null; ResultSet rs1 = null; String query=null; String query1=null; int ctr=0, flag=0; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); query="Select a.*,b.categoryname from book_details a, category_details b where a.categoryid=b.categoryid"; query1="select * from category_details"; stat = con.prepareStatement(query); stat1 = con.prepareStatement(query1); rs=stat.executeQuery(); rs1=stat1.executeQuery(); %> <br><h3>List of Available Books:</h3> <table border=1> <tr> <td>S.No</td> <td>Book Id</td> <td>Book Name</td> <td>Author Name</td> <td>Publisher</td> <td>Edition</td> <td>Price (in Rs.)</td> <td>Quantity Available(Nos.)</td> <td>Description</td> <td>Category</td> </tr> <% int int_BOOKID,int_CATEGORYID,int_PRICE,int_QUANTITY; String str_TITLE,str_AUTHOR,str_PUBLISHER,str_EDITION,str_DESCRIPTION; while(rs.next()) { ctr=ctr+1; out.println("<tr><td>"+ctr); int_BOOKID=rs.getInt(1); out.println("<td>"); out.println(int_BOOKID); int_CATEGORYID=rs.getInt(2);
73
str_TITLE=rs.getString(3); out.println("<td>"); out.println(str_TITLE); str_AUTHOR=rs.getString(4); out.println("<td>"); out.println(str_AUTHOR); str_PUBLISHER=rs.getString(5); out.println("<td>"); out.println(str_PUBLISHER); str_EDITION=rs.getString(6); out.println("<td>"); out.println(str_EDITION); int_PRICE=rs.getInt(7); out.println("<td>"); out.println(int_PRICE); int_QUANTITY=rs.getInt(8); out.println("<td>"); out.println(int_QUANTITY); str_DESCRIPTION=rs.getString(9); out.println("<td>"); out.println(str_DESCRIPTION); out.println("<td>"); out.println(rs.getString(10)); out.println("</tr>"); } out.println("</table>");%> <br> <hr> <h3> Add New Book Details</h3> <form name="addbook"> <table border=1> <tr><td>Book Title</td><td><input type="text" name="title"></td> <tr><td>Author Name</td><td><input type="text" name="author"></td> <tr><td>Publisher</td><td><input type="text" name="pub"></td> <tr><td>Edition</td><td><input type="text" name="edition"></td> <tr><td>Price (in Rs.)</td><td><input type="text" name="price"></td> <tr><td>Quantity Available(Nos.)</td><td><input type="text" name="qty"></td> <tr><td>Description</td><td><input type="text" name="desc"></td> <tr><td>Category</td><td><select size="1" name="cat"> <% while(rs1.next()) {%>
74
<option value="<%=rs1.getString(1)%>"><%=rs1.getString(2)%></option> <%}%> </select></td> </tr> <tr><td><input type="submit" value=" Add " onClick="check();"></td> <td><input type="Reset" value=" Clear "></td> </table> </form> <% } catch(Exception e) { out.print("Error = " + e + "<HR>"); } %> </BODY> </HTML>
75
int rs; String query=null; String query1=null; String TITLE; TITLE=request.getParameter("title"); query1="Select a.* from book_details a where a.title=?"; PreparedStatement stat1= con.prepareStatement(query1); stat1.setString(1,TITLE); rs1=stat1.executeQuery(); if(rs1.next()) { %> <SCRIPT language="JavaScript"> alert("This book already exists."); location.href="Insert.jsp"; </SCRIPT> <% } else { int int_BOOKID,int_CATEGORYID,int_PRICE,int_QUANTITY; String str_TITLE,str_AUTHOR,str_PUBLISHER,str_EDITION,str_DESCRIPTION; int_BOOKID=(int)(10000*Math.random()+1); int_CATEGORYID=Integer.parseInt(request.getParameter("cat")); str_TITLE=request.getParameter("title"); str_AUTHOR=request.getParameter("author"); str_PUBLISHER=request.getParameter("pub"); str_EDITION=request.getParameter("edition"); int_PRICE=Integer.parseInt(request.getParameter("price")); int_QUANTITY=Integer.parseInt(request.getParameter("qty")); str_DESCRIPTION=request.getParameter("desc"); query="insert into book_details values (?,?,?,?,?,?,?,?,?)"; stat = con.prepareStatement(query); stat.setInt(1,int_BOOKID); stat.setInt(2,int_CATEGORYID); stat.setString(3,str_TITLE); stat.setString(4,str_AUTHOR); stat.setString(5,str_PUBLISHER); stat.setString(6,str_EDITION); stat.setInt(7,int_PRICE); stat.setInt(8,int_QUANTITY); stat.setString(9,str_DESCRIPTION); rs=stat.executeUpdate(); if(rs==1) {%>
76
<BR> <H3>Successfully inserted the data.</H3> <% } else {%> <BR> <H3>Could not add the book</H3> <%} }%> <BR> <a href="Logout.jsp">Click here to logout</a> <BR><BR> <a href="Admin.htm">Click here to go to administrator page</a> <BR><BR> <a href="Insert.jsp"> Click here to add more books</a> </BODY> </HTML>
77
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); query="Select a.*,b.categoryname from book_details a, category_details b where a.categoryid=b.categoryid"; stat = con.prepareStatement(query); rs=stat.executeQuery(); %> <br><h3>List of Available Books:</h3> <form name="Mod" action="Modify_Book.jsp"> <table border=1> <tr> <td>S.No</td> <td>Book Id</td> <td>Book Name</td> <td>Author Name</td> <td>Publisher</td> <td>Edition</td> <td>Price (in Rs.)</td> <td>Quantity Available(Nos.)</td> <td>Description</td> <td>Category</td> </tr> <% int int_BOOKID,int_CATEGORYID,int_PRICE,int_QUANTITY; String str_TITLE,str_AUTHOR,str_PUBLISHER,str_EDITION,str_DESCRIPTION; while(rs.next()) { ctr=ctr+1; out.println("<tr><td>"+ctr); int_BOOKID=rs.getInt(1); out.println("<td>"); out.println("<input type=radio name=R1 value="+int_BOOKID+">"); int_CATEGORYID=rs.getInt(2); str_TITLE=rs.getString(3); out.println("<td>"); out.println(str_TITLE); str_AUTHOR=rs.getString(4); out.println("<td>"); out.println(str_AUTHOR); str_PUBLISHER=rs.getString(5); out.println("<td>"); out.println(str_PUBLISHER);
78
str_EDITION=rs.getString(6); out.println("<td>"); out.println(str_EDITION); int_PRICE=rs.getInt(7); out.println("<td>"); out.println(int_PRICE); int_QUANTITY=rs.getInt(8); out.println("<td>"); out.println(int_QUANTITY); str_DESCRIPTION=rs.getString(9); out.println("<td>"); out.println(str_DESCRIPTION); out.println("<td>"); out.println(rs.getString(10)); out.println("</tr>"); } %> <tr> <td><input type="submit" value=" Modify "></td> <td><input type="Reset" value=" Clear "></td> </tr> </table> </form> <% } catch(Exception e) { out.print("Error = " + e + "<HR>"); } %> </BODY> </HTML>
79
</CENTER> <HR> <BR> <BR> <a href="Logout.jsp" ><font size="4" >Click here to Logout</font></a> <%@ page errorPage="errorpage.jsp" import="java.net.*" %> <%@ page import="java.io.*" %> <%@ page import="java.sql.*" %> <% Connection con = null; PreparedStatement stat = null; ResultSet rs = null; String query=null; int book_sel = Integer.parseInt(request.getParameter("R1")); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:Data","scott","tiger");
query="Select a.*,b.categoryname from book_details a, category_details b where a.bookid=? and a.categoryid=b.categoryid"; stat = con.prepareStatement(query); stat.setInt(1,book_sel); rs=stat.executeQuery(); if(rs.next()) { %> <br><h3>Details of Selected Book:</h3> <form name="Mod" action="Final_Mod_Book.jsp"> <input type="hidden" name="categoryid" value="<%=rs.getString(2)%>"> <table border=1> <tr> <td>Book Id</td><td><input type="hidden" name="bookid" value="< %=book_sel%>"><%=book_sel%> </td></tr> <tr> <td>Book Name</td><td><input type="text" name="btitle" value=< %=rs.getString(3)%>></td> </tr><tr> <td>Author Name</td><td><input type="text" name="bauthor" value=< %=rs.getString(4)%>></td> </tr><tr> <td>Publisher</td><td><input type="text" name="bpub" value=< %=rs.getString(5)%>></td>
80
</tr><tr> <td>Edition</td><td><input type="text" name="bedition" value=< %=rs.getString(6)%>></td> </tr><tr> <td>Price (in Rs.)</td><td><input type="text" name="bprice" value=< %=rs.getString(7)%>></td> </tr><tr> <td>Quantity Available(Nos.)</td><td><input type="text" name="bqty" value=<%=rs.getString(8)%>></td> </tr><tr> <td>Description</td><td><input type="text" name="bdesc" value=< %=rs.getString(9)%>></td> </tr><tr> <td>Category</td><td><input type="text" name="bcat" value=< %=rs.getString(10)%>></td> </tr><tr> <tr><td><input type="submit" value=" Save Changes "></td><td><input type="Reset" value=" Clear "></td></tr> </table> </form> <% } } catch(Exception e) { out.print("Error = " + e + "<HR>"); } %> </BODY> </HTML>
81
<%@ page import="java.io.*" %> <%@ page import="java.sql.*" %> <% Connection con = null; //Statement stat = null; PreparedStatement stat = null; //Statement stat1 = null; PreparedStatement stat1 = null; ResultSet rs = null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); int rs_int; int int_BOOKID,int_CATEGORYID,int_PRICE,int_QUANTITY; String query=null; String str_TITLE,str_AUTHOR,str_PUBLISHER,str_EDITION,str_DESCRIPTION; int_BOOKID=Integer.parseInt(request.getParameter("bookid")); int_CATEGORYID=Integer.parseInt(request.getParameter("categoryid")); str_TITLE=request.getParameter("btitle"); str_AUTHOR=request.getParameter("bauthor"); str_PUBLISHER=request.getParameter("bpub"); str_EDITION=request.getParameter("bedition"); int_PRICE=Integer.parseInt(request.getParameter("bprice")); int_QUANTITY=Integer.parseInt(request.getParameter("bqty")); str_DESCRIPTION=request.getParameter("bdesc"); query="update book_details set categoryid=?,title=?,author=?,publisher=?,edition=?,price=?,quantity=?,description=? where bookid=?"; stat = con.prepareStatement(query); stat.setInt(1,int_CATEGORYID); stat.setString(2,str_TITLE); stat.setString(3,str_AUTHOR); stat.setString(4,str_PUBLISHER); stat.setString(5,str_EDITION); stat.setInt(6,int_PRICE); stat.setInt(7,int_QUANTITY); stat.setString(8,str_DESCRIPTION); stat.setInt(9,int_BOOKID); rs_int=stat.executeUpdate(); if (rs_int==1) {
82
out.println("Book details for Book Id "+int_BOOKID+" successfully modified."); } else { out.println("Sorry Transaction not Completed"); } %> <BR><BR> <a href="Logout.jsp">Click here to logout</a> <BR><BR> <a href="Admin.htm">Click here to go to administrator page</a> <BR><BR> <a href="Modify.jsp"> Click here to modify more books</a> </BODY> </HTML>
83
query="select * from category_details"; stat = con.prepareStatement(query); rs=stat.executeQuery(); %> <br><h3>Add New Category:</h3> <form name="addbook" action="AddCategory.jsp"> <table border=1> <tr> <td>Categories Available</td> <td><select size="1" name="cat"> <% while(rs.next()) {%> <option value="<%=rs.getString(1)%>">< %=rs.getString(2)%></option> <%}%> </select></td> </tr> <tr> <td>Category to be added</td> <td><input type="text" name="cat_name"></td></tr> <tr><td><input type="submit" value=" Add "></td><td><input type="Reset" value=" Clear "></td> </table></form> <% } catch(Exception e) { out.print("Error = " + e + "<HR>"); } finally { rs.close(); con.close(); } %> </BODY> </HTML>
84
<TITLE>Insert New Category</TITLE> </HEAD> <BODY bgcolor="#CCFFFF"> <CENTER> <H1> Administering Online Shopping Cart </H1> <H2> Add Category</H2> </CENTER> <BR> <HR> <BR> <%@ page errorPage="errorpage.jsp" import="java.net.*" %> <%@ page import="java.io.*" %> <%@ page import="java.sql.*" %> <% Connection con = null; PreparedStatement stat = null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); int rs; int int_CATEGORYID; String query=null; String str_CATEGORY; int_CATEGORYID=(int)(10000*Math.random()+1); str_CATEGORY=request.getParameter("cat_name"); query="insert into CATEGORY_details values (?,?)"; stat = con.prepareStatement(query); stat.setInt(1,int_CATEGORYID); stat.setString(2,str_CATEGORY); rs=stat.executeUpdate(); if (rs==1) { %><H3>New Category Successfully Added</H3><% } else { %><H3>Transaction Not Allowed</H3><% } %> <BR> <a href="Logout.jsp" ><font size="4" >Click here to Logout</font></a> <BR><BR>
85
<a href="Admin.htm"><font size="4" >Click here to go to administrator page</font></a> <BR><BR> <a href="Insert_Category.jsp"><font size="4" > Click here to add more categories</font></a> <BR><BR> </BODY> </HTML>
86
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); query="select * from category_details"; stat = con.prepareStatement(query); rs=stat.executeQuery(); %> <br><h2>Modify Category:--</h2> <form name="modcat" action="ModifyCategory.jsp"> <table border=1> <tr> <td>Category</td> <td><select size="1" name="cat" onChange="sel_click();"> <% while(rs.next()) {%> <option value="<%=rs.getString(1)%>"> <%=rs.getString(2)%></option> <%}%> </select></td> </tr> <tr><td colspan=2><input type="text" name="vr_cat"><input type="text" name="cat_val"></td> <tr><td><input type="submit" value=" Modify "></td><td><input type="Reset" value=" Clear "></td> </table></form> <% } catch(Exception e) { // out.print("Error = " + e + "<HR>"); } finally { rs.close(); con.close(); } %> </BODY> </HTML>
87
</HEAD> <BODY bgcolor="#CCFFFF"> <CENTER> <H1> Administering Online Shopping Cart </H1> </CENTER> <BR> <HR> <BR> <BR> <%@ page errorPage="errorpage.jsp" import="java.net.*" %> <%@ page import="java.io.*" %> <%@ page import="java.sql.*" %> <% Connection con = null; PreparedStatement stat = null; int rs = 0; String query=null; try { String new_cat=""; int cat_id=0; new_cat=request.getParameter("vr_cat"); cat_id=Integer.parseInt(request.getParameter("cat_val")); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:Data","scott","tiger"); query="UPDATE category_details SET CATEGORYNAME=? WHERE CATEGORYID=?"; stat = con.prepareStatement(query); stat.setString(1,new_cat); stat.setInt(2,cat_id); rs=stat.executeUpdate(); if (rs==1) { out.println("Category Successfully Modified"); } else { out.println("Transaction Not Allowed"); } } catch(Exception e)
88
{ out.print("Error = " + e + "<HR>"); } finally { con.close(); } %> <BR> <BR> <a href="Logout.jsp">Click here to logout</a> <BR><BR> <a href="Admin.htm">Click here to go to administrator page</a> <BR><BR> <a href="Update_Category.jsp"> Click here to modify more categories</a> </BODY> </HTML>
89