diff --git a/Sanchit/WebContent/AddBook.html b/Sanchit/WebContent/AddBook.html new file mode 100644 index 0000000..ff5e4a7 --- /dev/null +++ b/Sanchit/WebContent/AddBook.html @@ -0,0 +1,22 @@ + + + + +Add Book + + +

ADD BOOK

+ +

+
+	ISBN Number : 
+ Book Name :
+ Book Type :
+ Author Code :
+ Cost :
+
+
+
+ + + \ No newline at end of file diff --git a/Sanchit/WebContent/Failure.html b/Sanchit/WebContent/Failure.html new file mode 100644 index 0000000..7966303 --- /dev/null +++ b/Sanchit/WebContent/Failure.html @@ -0,0 +1,10 @@ + + + + +Insert title here + + +The operation could not be completed + + \ No newline at end of file diff --git a/Sanchit/WebContent/Invalid.html b/Sanchit/WebContent/Invalid.html new file mode 100644 index 0000000..6746115 --- /dev/null +++ b/Sanchit/WebContent/Invalid.html @@ -0,0 +1,10 @@ + + + + +Insert title here + + +Sorry You have given invalid data + + \ No newline at end of file diff --git a/Sanchit/WebContent/META-INF/MANIFEST.MF b/Sanchit/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5e94951 --- /dev/null +++ b/Sanchit/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/Sanchit/WebContent/Menu.html b/Sanchit/WebContent/Menu.html new file mode 100644 index 0000000..bfac08c --- /dev/null +++ b/Sanchit/WebContent/Menu.html @@ -0,0 +1,12 @@ + + + + +Menu + + +

Main Menu


+Add Book
+View Book
+ + \ No newline at end of file diff --git a/Sanchit/WebContent/ViewBook.html b/Sanchit/WebContent/ViewBook.html new file mode 100644 index 0000000..781399d --- /dev/null +++ b/Sanchit/WebContent/ViewBook.html @@ -0,0 +1,14 @@ + + + + +View Book + + +

View Book

+
+ ISBN :
+ +
+ + \ No newline at end of file diff --git a/Sanchit/WebContent/WEB-INF/lib/ojdbc14.jar b/Sanchit/WebContent/WEB-INF/lib/ojdbc14.jar new file mode 100644 index 0000000..0aa1b51 Binary files /dev/null and b/Sanchit/WebContent/WEB-INF/lib/ojdbc14.jar differ diff --git a/Sanchit/WebContent/WEB-INF/web.xml b/Sanchit/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..5cb886e --- /dev/null +++ b/Sanchit/WebContent/WEB-INF/web.xml @@ -0,0 +1,12 @@ + + + LMS + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + \ No newline at end of file diff --git a/Sanchit/build/classes/com/wipro/book/bean/AuthorBean.class b/Sanchit/build/classes/com/wipro/book/bean/AuthorBean.class new file mode 100644 index 0000000..3649385 Binary files /dev/null and b/Sanchit/build/classes/com/wipro/book/bean/AuthorBean.class differ diff --git a/Sanchit/build/classes/com/wipro/book/bean/BookBean.class b/Sanchit/build/classes/com/wipro/book/bean/BookBean.class new file mode 100644 index 0000000..2320eda Binary files /dev/null and b/Sanchit/build/classes/com/wipro/book/bean/BookBean.class differ diff --git a/Sanchit/build/classes/com/wipro/book/dao/AuthorDao.class b/Sanchit/build/classes/com/wipro/book/dao/AuthorDao.class new file mode 100644 index 0000000..c2532af Binary files /dev/null and b/Sanchit/build/classes/com/wipro/book/dao/AuthorDao.class differ diff --git a/Sanchit/build/classes/com/wipro/book/dao/BookDao.class b/Sanchit/build/classes/com/wipro/book/dao/BookDao.class new file mode 100644 index 0000000..a6c7f25 Binary files /dev/null and b/Sanchit/build/classes/com/wipro/book/dao/BookDao.class differ diff --git a/Sanchit/build/classes/com/wipro/book/service/Administrator.class b/Sanchit/build/classes/com/wipro/book/service/Administrator.class new file mode 100644 index 0000000..c0c1577 Binary files /dev/null and b/Sanchit/build/classes/com/wipro/book/service/Administrator.class differ diff --git a/Sanchit/build/classes/com/wipro/book/servlets/MainServlet.class b/Sanchit/build/classes/com/wipro/book/servlets/MainServlet.class new file mode 100644 index 0000000..0ae3583 Binary files /dev/null and b/Sanchit/build/classes/com/wipro/book/servlets/MainServlet.class differ diff --git a/Sanchit/build/classes/com/wipro/book/util/CreateTable.class b/Sanchit/build/classes/com/wipro/book/util/CreateTable.class new file mode 100644 index 0000000..2831156 Binary files /dev/null and b/Sanchit/build/classes/com/wipro/book/util/CreateTable.class differ diff --git a/Sanchit/build/classes/com/wipro/book/util/DBUtil.class b/Sanchit/build/classes/com/wipro/book/util/DBUtil.class new file mode 100644 index 0000000..3daa66c Binary files /dev/null and b/Sanchit/build/classes/com/wipro/book/util/DBUtil.class differ diff --git a/Sanchit/src/com/wipro/book/bean/AuthorBean.java b/Sanchit/src/com/wipro/book/bean/AuthorBean.java new file mode 100644 index 0000000..fd11ff2 --- /dev/null +++ b/Sanchit/src/com/wipro/book/bean/AuthorBean.java @@ -0,0 +1,26 @@ +package com.wipro.book.bean; + +public class AuthorBean { + private int authorCode; + private String authorName; + private long contactNumber; + public int getAuthorCode() { + return authorCode; + } + public void setAuthorCode(int authorCode) { + this.authorCode = authorCode; + } + public String getAuthorName() { + return authorName; + } + public void setAuthorName(String authorName) { + this.authorName = authorName; + } + public long getContactNumber() { + return contactNumber; + } + public void setContactNumber(long contactNumber) { + this.contactNumber = contactNumber; + } + +} diff --git a/Sanchit/src/com/wipro/book/bean/BookBean.java b/Sanchit/src/com/wipro/book/bean/BookBean.java new file mode 100644 index 0000000..79cd936 --- /dev/null +++ b/Sanchit/src/com/wipro/book/bean/BookBean.java @@ -0,0 +1,42 @@ +package com.wipro.book.bean; + +public class BookBean { + private String isbn; + public String getIsbn() { + return isbn; + } + public void setIsbn(String isbn) { + this.isbn = isbn; + } + public String getBookName() { + return bookName; + } + public void setBookName(String bookName) { + this.bookName = bookName; + } + public AuthorBean getAuthor() { + return author; + } + public void setAuthor(AuthorBean author) { + this.author = author; + } + public char getBookType() { + return bookType; + } + public void setBookType(char bookType) { + this.bookType = bookType; + } + public float getCost() { + return cost; + } + public void setCost(float cost) { + this.cost = cost; + } + private String bookName; + private AuthorBean author; + private char bookType; + private float cost; + + + +} diff --git a/Sanchit/src/com/wipro/book/dao/AuthorDao.java b/Sanchit/src/com/wipro/book/dao/AuthorDao.java new file mode 100644 index 0000000..b1c241d --- /dev/null +++ b/Sanchit/src/com/wipro/book/dao/AuthorDao.java @@ -0,0 +1,59 @@ +package com.wipro.book.dao; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import com.wipro.book.bean.AuthorBean; +import com.wipro.book.util.DBUtil; + +public class AuthorDao { + public AuthorBean getAuthor(int authorCode){ + Connection conn = DBUtil.getDBConnection(); + PreparedStatement ps; + try { + ps = conn.prepareStatement("select * from author_tbl_me12 where author_code=?"); + ps.setInt(1, authorCode); + ResultSet rs = ps.executeQuery(); + AuthorBean bean = null; + while(rs.next()){ + bean = new AuthorBean(); + bean.setAuthorCode(authorCode); + bean.setAuthorName(rs.getString(2)); + bean.setContactNumber(rs.getLong(3)); + } + return bean; + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch(NullPointerException e){ + System.out.println("error"+authorCode); + } + + return null; + } + + public AuthorBean getAuthor(String authorName){ + Connection conn = DBUtil.getDBConnection(); + PreparedStatement ps; + try { + ps = conn.prepareStatement("select * from author_tbl_me12 where author_name=?"); + ps.setString(1, authorName); + ResultSet rs = ps.executeQuery(); + AuthorBean bean = new AuthorBean(); + while(rs.next()){ + bean.setAuthorCode(rs.getInt(1)); + bean.setAuthorName(rs.getString(2)); + bean.setContactNumber(rs.getLong(3)); + } + return bean; + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } +} diff --git a/Sanchit/src/com/wipro/book/dao/BookDao.java b/Sanchit/src/com/wipro/book/dao/BookDao.java new file mode 100644 index 0000000..5c759c9 --- /dev/null +++ b/Sanchit/src/com/wipro/book/dao/BookDao.java @@ -0,0 +1,60 @@ +package com.wipro.book.dao; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import com.wipro.book.bean.BookBean; +import com.wipro.book.util.DBUtil; + +public class BookDao { + public BookBean fetchBook(String ISBN){ + Connection conn = DBUtil.getDBConnection(); + PreparedStatement ps; + try { + ps = conn.prepareStatement("select * from book_tbl_me12 where ISBN=?"); + ps.setString(1, ISBN); + ResultSet rs = ps.executeQuery(); + BookBean bean =null; + while(rs.next()){ + bean = new BookBean(); + bean.setIsbn(ISBN); + bean.setBookName(rs.getString(2)); + bean.setBookType(rs.getString(3).charAt(0)); + bean.setAuthor( new AuthorDao().getAuthor(rs.getInt(4))); + bean.setCost(rs.getFloat(5)); + } + return bean; + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch(NullPointerException e){ + System.out.println("error"+ISBN); + + } + + return null; + } + + public int createBook(BookBean book){ + Connection conn = DBUtil.getDBConnection(); + try { + PreparedStatement ps = conn.prepareStatement("insert into book_tbl_me12 values(?,?,?,?,?)"); + ps.setString(1, book.getIsbn()); + ps.setString(2, book.getBookName()); + ps.setString(3,((Character)book.getBookType()).toString()); + ps.setInt(4, book.getAuthor().getAuthorCode()); + ps.setFloat(5, book.getCost()); + ps.execute(); + return 1; + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return 0; + } + + + } + +} diff --git a/Sanchit/src/com/wipro/book/service/Administrator.java b/Sanchit/src/com/wipro/book/service/Administrator.java new file mode 100644 index 0000000..02c8703 --- /dev/null +++ b/Sanchit/src/com/wipro/book/service/Administrator.java @@ -0,0 +1,26 @@ +package com.wipro.book.service; + +import com.wipro.book.bean.BookBean; +import com.wipro.book.dao.BookDao; + +public class Administrator { + public String addBook(BookBean bean){ + if(bean==null||bean.getBookName().equals("")||bean.getIsbn().equals("")||bean.getBookType()!='T'&&bean.getBookType()!='G'||bean.getCost()<=0||bean.getAuthor().getAuthorName()==null||bean.getAuthor().getAuthorName().equals("")){ + return "INVALID"; + } + int res = new BookDao().createBook(bean); + if(res == 1){ + return "SUCCESS"; + + } + else{ + return "FAILURE"; + } + } + public BookBean viewBook(String isbn){ + if(isbn.equals("")) + return null; + return new BookDao().fetchBook(isbn); + } + +} diff --git a/Sanchit/src/com/wipro/book/servlets/MainServlet.java b/Sanchit/src/com/wipro/book/servlets/MainServlet.java new file mode 100644 index 0000000..ba0cd7f --- /dev/null +++ b/Sanchit/src/com/wipro/book/servlets/MainServlet.java @@ -0,0 +1,111 @@ +package com.wipro.book.servlets; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.wipro.book.bean.BookBean; +import com.wipro.book.dao.AuthorDao; +import com.wipro.book.service.Administrator; + +/** + * Servlet implementation class MainServlet + */ +@WebServlet("/MainServlet") +public class MainServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public MainServlet() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + response.getWriter().append("Served at: ").append(request.getContextPath()); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + String operation = request.getParameter("operation"); + if(operation.equals("AddBook")){ + String result = addBook(request); + + if(result.equals("SUCCESS")){ + RequestDispatcher rd = request.getRequestDispatcher("/Menu.html"); + rd.include(request, response); + } + else if(result.equals("FAILURE")){ + RequestDispatcher rd = request.getRequestDispatcher("Failure.html"); + rd.include(request, response); + } + else{ + RequestDispatcher rd = request.getRequestDispatcher("Invalid.html"); + rd.include(request, response); + } + } + if(operation.equals("Search")){ + BookBean bean = viewBook(request.getParameter("isbn")); + if(bean==null){ + RequestDispatcher rd = request.getRequestDispatcher("Invalid.html"); + rd.include(request, response); + return; + } + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println("View Book"); + String type=""; + if(bean.getBookType()=='T') + type = "Technical"; + else if(bean.getBookType()=='G') + type = "General"; + else{ + RequestDispatcher rd = request.getRequestDispatcher("Failure.html"); + rd.forward(request, response); + return; + } + + out.println(""); + out.println(""); + out.println(""); + out.println(""); + out.println(""); + out.println("
ISBN"+bean.getIsbn()+"
Book Name"+bean.getBookName()+"
Book Type"+type+"
Author Name"+bean.getAuthor().getAuthorName()+"
Contact"+bean.getAuthor().getContactNumber()+"
Cost"+bean.getCost()+"
"); + out.println(""); + out.close(); + + } + } + + public String addBook(HttpServletRequest request){ + Administrator admin = new Administrator(); + BookBean bean = new BookBean(); + bean.setIsbn(request.getParameter("isbn")); + bean.setBookName(request.getParameter("bookname")); + bean.setBookType(request.getParameter("booktype").charAt(0)); + bean.setAuthor(( new AuthorDao()).getAuthor(Integer.parseInt(request.getParameter("author")) )); + bean.setCost(Float.parseFloat(request.getParameter("cost"))); + return admin.addBook(bean); + } + + + public BookBean viewBook(String isbn){ + return new Administrator().viewBook(isbn); + } + +} diff --git a/Sanchit/src/com/wipro/book/util/CreateTable.java b/Sanchit/src/com/wipro/book/util/CreateTable.java new file mode 100644 index 0000000..f01f71d --- /dev/null +++ b/Sanchit/src/com/wipro/book/util/CreateTable.java @@ -0,0 +1,40 @@ +package com.wipro.book.util; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; + +public class CreateTable { + + public static void main(String[] args) { + // TODO Auto-generated method stub + try{ + Class.forName("oracle.jdbc.driver.OracleDriver"); + Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@orcl.rmk.ac.in:1521:ORCL","scott","tiger"); + System.out.println("success"); + Statement stmt = conn.createStatement(); + stmt.executeQuery("drop table book_tbl_me12"); + stmt.executeQuery("drop table author_tbl_me12"); + stmt.executeQuery("create table author_tbl_me12(author_code number(5) primary key,author_name varchar2(20) not null,contact_no number(10))"); + stmt.executeQuery("create table book_tbl_me12(ISBN varchar2(10) primary key,book_title varchar2(20) not null,book_type char(1),author_code number(5) not null,book_cost number(15,2) not null,constraint bk_ck check(book_type='T' or book_type='G'),constraint au_fk foreign key(author_code) references author_tbl_me12(author_code))"); + stmt.executeQuery("insert into author_tbl_me12 values (1,'RobinSharma',8800799224)"); + stmt.executeQuery("insert into author_tbl_me12 values (2,'R.K.Narayan',8800799255)"); + stmt.executeQuery("insert into author_tbl_me12 values (3,'Paulo',8800799775)"); + + } + catch(ClassNotFoundException e) + { + System.out.println("Driver Not Found"); + + } + catch(SQLException e) + { + System.out.println("Could not connect to database"); + e.printStackTrace(); + + } + return; + } + +} diff --git a/Sanchit/src/com/wipro/book/util/DBUtil.java b/Sanchit/src/com/wipro/book/util/DBUtil.java new file mode 100644 index 0000000..c9955ea --- /dev/null +++ b/Sanchit/src/com/wipro/book/util/DBUtil.java @@ -0,0 +1,29 @@ +package com.wipro.book.util; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class DBUtil { + public static Connection getDBConnection() + { + try{ + Class.forName("oracle.jdbc.driver.OracleDriver"); + Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@orcl.rmk.ac.in:1521:ORCL","scott","tiger"); + return conn; + } + catch(ClassNotFoundException e) + { + System.out.println("Driver Not Found"); + + } + catch(SQLException e) + { + System.out.println("Could not connect to database"); + e.printStackTrace(); + + } + return null; + + } +}