Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- myserve\\\\\\
- package com.controller;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import javax.servlet.RequestDispatcher;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.Service.frndService;
- import com.bean.friends;
- /**
- * Servlet implementation class myServe
- */
- public class myServe extends HttpServlet {
- private static final long serialVersionUID = 1L;
- /**
- * @see HttpServlet#HttpServlet()
- */
- public myServe() {
- super();
- // TODO Auto-generated constructor stub
- }
- /**
- * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- String action = request.getParameter("action");
- PrintWriter out = response.getWriter();
- if(action!=null && action.equalsIgnoreCase("View"))
- {
- frndService s= new frndService();
- ArrayList<friends> alist = null;
- try {
- alist = s.getfriendsDetails();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- if(alist!=null){
- request.setAttribute("list", alist);
- RequestDispatcher rd=request.getRequestDispatcher("View.jsp");
- rd.forward(request, response);
- }
- else{
- RequestDispatcher rd=request.getRequestDispatcher("Error.html");
- rd.forward(request, response);
- }
- }
- else if(action!=null && action.equalsIgnoreCase("Search"))
- {
- String name= request.getParameter("name");
- frndService s= new frndService();
- friends alist = null;
- try {
- alist = s.SearchFriend(name);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- if(alist!=null){
- request.setAttribute("list", alist);
- RequestDispatcher rd=request.getRequestDispatcher("View2.jsp");
- rd.forward(request, response);
- }
- else{
- RequestDispatcher rd=request.getRequestDispatcher("Error.html");
- rd.forward(request, response);
- }
- }
- }
- /**
- * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- PrintWriter out= response.getWriter();
- String Name= request.getParameter("name");
- int Lg= Integer.parseInt(request.getParameter("lg"));
- int Contact= Integer.parseInt(request.getParameter("contact"));
- String Stream= request.getParameter("stream");
- friends f= new friends(Name,Lg,Stream,Contact);
- frndService s= new frndService();
- int update=0;
- try {
- update = s.insertFriend(f);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- if(update > 0){
- out.print("<h6 align=left>");
- out.print("<a href=Home.html>HOME</a>");
- out.print("</h6>");
- out.print("<h1 align=center> Customer "+ f.getName()+" has been successfully added :) </h1>");
- out.print("<h6 align=center>");
- out.print("<a href=myServe?action=view> View List</a>");
- out.print("</h6>");
- }
- else{
- out.print("<h6 align=left>");
- out.print("<a href=home.html>HOME</a>");
- out.print("</h6>");
- out.print("<h1 align=center> Customer "+ Name +" is not added :( </h1>");
- }
- }
- }
- \\\\\\\\\
- package com.Dao;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import com.bean.friends;
- import com.util.DbTransaction;
- public class friendsdao {
- public int insertFrnd(friends f) throws SQLException {
- DbTransaction db = new DbTransaction();
- Connection conn = db.getConnection();
- PreparedStatement st = null;
- String sql = "INSERT INTO tbl_ilpfrnd VALUES (?,?,?,?)";
- st = conn.prepareStatement(sql);
- st.setString(1, f.getName());
- st.setInt(2, f.getLg());
- st.setString(3, f.getStream());
- st.setInt(4, f.getContact());
- int rs = st.executeUpdate();
- return rs;
- }
- public ArrayList<friends> getfriendsDetails() throws SQLException {
- ArrayList<friends> alist = new ArrayList<friends>();
- DbTransaction db = new DbTransaction();
- Connection conn = db.getConnection();
- PreparedStatement st = null;
- try {
- st = conn.prepareStatement("select * from tbl_ilpfrnd");
- ResultSet rs = st.executeQuery();
- while (rs.next()) {
- friends a = new friends();
- a.setName(rs.getString(1));
- a.setLg(rs.getInt(2));
- a.setStream(rs.getString(3));
- a.setContact(rs.getInt(4));
- alist.add(a);
- }
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- System.out.println(alist);
- return alist;
- }
- public friends searchFriend(String name) {
- DbTransaction db = new DbTransaction();
- Connection conn = db.getConnection();
- PreparedStatement st = null;
- try {
- String sql = "select * from " + db.getTableName() + " where Name=?";
- System.err.println(sql);
- st = conn.prepareStatement(sql);
- st.setString(1, name);
- ResultSet rs = st.executeQuery();
- while (rs.next()) {
- friends a = new friends();
- a.setName(rs.getString(1));
- a.setLg(rs.getInt(2));
- a.setStream(rs.getString(3));
- a.setContact(rs.getInt(4));
- System.out.println(a);
- return a;
- }
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- return null;
- }
- }
- \\\\\\\\\\\\
- package com.Service;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import com.Dao.friendsdao;
- import com.bean.friends;
- public class frndService {
- //Insert Friend
- public int insertFriend(friends f) throws SQLException {
- friendsdao dao = new friendsdao();
- return dao.insertFrnd(f);
- }
- //Friend List
- public ArrayList<friends> getfriendsDetails() throws SQLException {
- friendsdao dao = new friendsdao();
- ArrayList<friends> list = new ArrayList<friends>();
- list = dao.getfriendsDetails();
- return list;
- }
- //Search Friend
- public friends SearchFriend(String name) throws SQLException{
- friendsdao dao = new friendsdao();
- return dao.searchFriend(name);
- }
- }
- \\\\\\\\\\\\\
- package com.util;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class DbTransaction {
- private String url= "jdbc:oracle:thin:@INGNRGPILPHP01:1521:ORCLILP";
- private String user= "aja170core";
- private String password= "aja170core";
- private Connection connection;
- private String tableName = "tbl_ilp_friend";
- public String getTableName() {
- return tableName;
- }
- public Connection getConnection() {
- try {
- closeConnection();
- Class.forName("oracle.jdbc.driver.OracleDriver");
- connection = DriverManager.getConnection(url, user, password);
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- return connection;
- }
- public void closeConnection() {
- try {
- if (connection != null && connection.isClosed() == false)
- connection.close();
- connection = null;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- \\\\\\\\\\\\
- homee
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="ISO-8859-1">
- <title>Home Page</title>
- </head>
- <body>
- <h1 align="center">ILP Friends</h1>
- <p align="center">
- <a href="Register.html">Add Friends</a>
- </p>
- <p align="center">
- <a href="Search.html"> Search List</a>
- </p>
- <p align="center">
- <a href="myServe?action=View"> Friend List</a>
- </p>
- <br></br>
- <h6 align="center">deepak.1@tcs.com</h6>
- </body>
- </html>
- \\\\\\\\\\\\\
- registerr
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="ISO-8859-1">
- <title>Registration Page</title>
- </head>
- <body>
- <h6 align="left">
- <a href="home.html">HOME</a>
- </h6>
- <h1 align="center">Friends Adding Form</h1>
- <div align=center>
- <form action="myServe" method="post">
- <table>
- <tr>
- <td>Full Name :</td>
- <td><input type="text" name="name" placeholder="Full Name" required maxlength=""></td>
- </tr>
- <tr>
- <td>LG Number :</td>
- <td><input type="text" name="lg" placeholder="LG No."></td>
- </tr>
- <tr>
- <td>Stream:</td>
- <td><input type="text" name="stream" placeholder="Stream"></td>
- </tr>
- <tr>
- <td>Contact Number</td>
- <td><input type="text" name="contact" placeholder="Contact"></td>
- </tr>
- </table>
- <br>
- <p align="center">
- <input type="submit" Value="SUBMIT">
- </p>
- </form>
- </div>
- <br></br>
- <h6 align="center">shahnawaz.md1@tcs.com</h6>
- </body>
- </html>
- \\\\\\\\\\
- searchh
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="ISO-8859-1">
- <title>Search Page</title>
- </head>
- <body>
- <h6 align="left">
- <a href="home.html">HOME</a>
- </h6>
- <h1 align="center">Search Friend</h1>
- <div align=center>
- <form action="myServe?action=SEARCH" method="get">
- <table>
- <tr>
- <td>Full Name :</td>
- <td><input type="text" name="name" placeholder="Full Name"></td>
- </tr>
- </table>
- <br>
- <p align="center">
- <input type="submit" Value="SEARCH" name="action">
- </p>
- </form>
- <br></br>
- <h6 align="center">deepak@tcs.com</h6>
- </body>
- </html>
- \\\\\\\\\\\
- view
- <%@page import="com.bean.friends"%>
- <%@page import="java.util.ArrayList"%>
- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <h6 align="left">
- <a href="Home.html">HOME</a>
- </h6>
- <h1 align="center">List Of Friends</h1>
- <%
- ArrayList<friends> list = new ArrayList<>();
- list = (ArrayList<friends>) request.getAttribute("list");
- %>
- <div align="center">
- <table border='1' width='5'>
- <tr>
- <th>Name</th>
- <th>L Group</th>
- <th>Stream</th>
- <th>contact</th>
- <th>Action</th>
- </tr>
- <%
- for (friends f:list) {
- %>
- <tr>
- <td><%=f.getName()%></td>
- <td><%=f.getLg()%></td>
- <td><%=f.getStream()%></td>
- <td><%=f.getContact()%></td>
- <td><a href="">Delete</a></td>
- </tr>
- <%
- }
- %>
- </table>
- </div>
- <br></br>
- <h6 align="center">dkt@tcs.com</h6>
- </body>
- </html>
- \\\\\\\\
- qwertry
- create table tbl_ilpfrnd(
- Name varchar(20),
- Lg int,
- Stream varchar(20),
- Contact int
- );
- select * from tbl_ilpfrnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement