Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.80 KB | None | 0 0
  1. myserve\\\\\\
  2. package com.controller;
  3.  
  4. import java.io.IOException;
  5. import java.io.PrintWriter;
  6. import java.sql.SQLException;
  7. import java.util.ArrayList;
  8.  
  9. import javax.servlet.RequestDispatcher;
  10. import javax.servlet.ServletException;
  11. import javax.servlet.http.HttpServlet;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14.  
  15. import com.Service.frndService;
  16. import com.bean.friends;
  17.  
  18. /**
  19. * Servlet implementation class myServe
  20. */
  21. public class myServe extends HttpServlet {
  22. private static final long serialVersionUID = 1L;
  23.  
  24. /**
  25. * @see HttpServlet#HttpServlet()
  26. */
  27. public myServe() {
  28. super();
  29. // TODO Auto-generated constructor stub
  30. }
  31.  
  32. /**
  33. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  34. */
  35. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  36.  
  37. String action = request.getParameter("action");
  38. PrintWriter out = response.getWriter();
  39.  
  40. if(action!=null && action.equalsIgnoreCase("View"))
  41. {
  42. frndService s= new frndService();
  43.  
  44. ArrayList<friends> alist = null;
  45. try {
  46. alist = s.getfriendsDetails();
  47. } catch (SQLException e) {
  48. e.printStackTrace();
  49. }
  50. if(alist!=null){
  51. request.setAttribute("list", alist);
  52. RequestDispatcher rd=request.getRequestDispatcher("View.jsp");
  53. rd.forward(request, response);
  54. }
  55. else{
  56. RequestDispatcher rd=request.getRequestDispatcher("Error.html");
  57. rd.forward(request, response);
  58. }
  59. }
  60.  
  61. else if(action!=null && action.equalsIgnoreCase("Search"))
  62. {
  63. String name= request.getParameter("name");
  64.  
  65. frndService s= new frndService();
  66.  
  67. friends alist = null;
  68. try {
  69. alist = s.SearchFriend(name);
  70. } catch (SQLException e) {
  71. e.printStackTrace();
  72. }
  73. if(alist!=null){
  74. request.setAttribute("list", alist);
  75. RequestDispatcher rd=request.getRequestDispatcher("View2.jsp");
  76. rd.forward(request, response);
  77. }
  78. else{
  79. RequestDispatcher rd=request.getRequestDispatcher("Error.html");
  80. rd.forward(request, response);
  81. }
  82. }
  83. }
  84.  
  85.  
  86. /**
  87. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  88. */
  89. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  90.  
  91. PrintWriter out= response.getWriter();
  92.  
  93. String Name= request.getParameter("name");
  94. int Lg= Integer.parseInt(request.getParameter("lg"));
  95. int Contact= Integer.parseInt(request.getParameter("contact"));
  96. String Stream= request.getParameter("stream");
  97.  
  98. friends f= new friends(Name,Lg,Stream,Contact);
  99.  
  100. frndService s= new frndService();
  101.  
  102. int update=0;
  103.  
  104. try {
  105. update = s.insertFriend(f);
  106. } catch (SQLException e) {
  107. e.printStackTrace();
  108. }
  109.  
  110. if(update > 0){
  111. out.print("<h6 align=left>");
  112. out.print("<a href=Home.html>HOME</a>");
  113. out.print("</h6>");
  114. out.print("<h1 align=center> Customer "+ f.getName()+" has been successfully added :) </h1>");
  115. out.print("<h6 align=center>");
  116. out.print("<a href=myServe?action=view> View List</a>");
  117. out.print("</h6>");
  118. }
  119. else{
  120. out.print("<h6 align=left>");
  121. out.print("<a href=home.html>HOME</a>");
  122. out.print("</h6>");
  123. out.print("<h1 align=center> Customer "+ Name +" is not added :( </h1>");
  124. }
  125.  
  126. }
  127. }
  128.  
  129. \\\\\\\\\
  130.  
  131. package com.Dao;
  132.  
  133. import java.sql.Connection;
  134. import java.sql.PreparedStatement;
  135. import java.sql.ResultSet;
  136. import java.sql.SQLException;
  137. import java.util.ArrayList;
  138.  
  139. import com.bean.friends;
  140. import com.util.DbTransaction;
  141.  
  142. public class friendsdao {
  143.  
  144. public int insertFrnd(friends f) throws SQLException {
  145. DbTransaction db = new DbTransaction();
  146. Connection conn = db.getConnection();
  147. PreparedStatement st = null;
  148. String sql = "INSERT INTO tbl_ilpfrnd VALUES (?,?,?,?)";
  149. st = conn.prepareStatement(sql);
  150.  
  151. st.setString(1, f.getName());
  152. st.setInt(2, f.getLg());
  153. st.setString(3, f.getStream());
  154. st.setInt(4, f.getContact());
  155.  
  156. int rs = st.executeUpdate();
  157. return rs;
  158. }
  159.  
  160. public ArrayList<friends> getfriendsDetails() throws SQLException {
  161.  
  162. ArrayList<friends> alist = new ArrayList<friends>();
  163. DbTransaction db = new DbTransaction();
  164. Connection conn = db.getConnection();
  165. PreparedStatement st = null;
  166.  
  167. try {
  168. st = conn.prepareStatement("select * from tbl_ilpfrnd");
  169.  
  170. ResultSet rs = st.executeQuery();
  171. while (rs.next()) {
  172. friends a = new friends();
  173. a.setName(rs.getString(1));
  174. a.setLg(rs.getInt(2));
  175. a.setStream(rs.getString(3));
  176. a.setContact(rs.getInt(4));
  177.  
  178. alist.add(a);
  179.  
  180. }
  181. } catch (SQLException e) {
  182. System.out.println(e.getMessage());
  183. }
  184. System.out.println(alist);
  185. return alist;
  186. }
  187.  
  188. public friends searchFriend(String name) {
  189.  
  190. DbTransaction db = new DbTransaction();
  191. Connection conn = db.getConnection();
  192. PreparedStatement st = null;
  193.  
  194. try {
  195.  
  196. String sql = "select * from " + db.getTableName() + " where Name=?";
  197. System.err.println(sql);
  198. st = conn.prepareStatement(sql);
  199. st.setString(1, name);
  200.  
  201. ResultSet rs = st.executeQuery();
  202. while (rs.next()) {
  203. friends a = new friends();
  204. a.setName(rs.getString(1));
  205. a.setLg(rs.getInt(2));
  206. a.setStream(rs.getString(3));
  207. a.setContact(rs.getInt(4));
  208. System.out.println(a);
  209. return a;
  210. }
  211. } catch (SQLException e) {
  212. System.out.println(e.getMessage());
  213. }
  214. return null;
  215. }
  216.  
  217. }
  218.  
  219.  
  220. \\\\\\\\\\\\
  221.  
  222.  
  223. package com.Service;
  224.  
  225. import java.sql.SQLException;
  226. import java.util.ArrayList;
  227.  
  228. import com.Dao.friendsdao;
  229. import com.bean.friends;
  230.  
  231. public class frndService {
  232.  
  233. //Insert Friend
  234. public int insertFriend(friends f) throws SQLException {
  235. friendsdao dao = new friendsdao();
  236. return dao.insertFrnd(f);
  237. }
  238. //Friend List
  239. public ArrayList<friends> getfriendsDetails() throws SQLException {
  240. friendsdao dao = new friendsdao();
  241. ArrayList<friends> list = new ArrayList<friends>();
  242. list = dao.getfriendsDetails();
  243. return list;
  244. }
  245. //Search Friend
  246. public friends SearchFriend(String name) throws SQLException{
  247. friendsdao dao = new friendsdao();
  248. return dao.searchFriend(name);
  249. }
  250.  
  251. }
  252.  
  253.  
  254.  
  255.  
  256. \\\\\\\\\\\\\
  257.  
  258. package com.util;
  259.  
  260. import java.sql.Connection;
  261. import java.sql.DriverManager;
  262. import java.sql.SQLException;
  263.  
  264. public class DbTransaction {
  265.  
  266. private String url= "jdbc:oracle:thin:@INGNRGPILPHP01:1521:ORCLILP";
  267. private String user= "aja170core";
  268. private String password= "aja170core";
  269. private Connection connection;
  270. private String tableName = "tbl_ilp_friend";
  271.  
  272. public String getTableName() {
  273. return tableName;
  274. }
  275.  
  276. public Connection getConnection() {
  277. try {
  278. closeConnection();
  279. Class.forName("oracle.jdbc.driver.OracleDriver");
  280. connection = DriverManager.getConnection(url, user, password);
  281.  
  282. } catch (SQLException e) {
  283. e.printStackTrace();
  284.  
  285. } catch (ClassNotFoundException e) {
  286.  
  287. e.printStackTrace();
  288. }
  289.  
  290. return connection;
  291. }
  292.  
  293. public void closeConnection() {
  294.  
  295. try {
  296. if (connection != null && connection.isClosed() == false)
  297. connection.close();
  298. connection = null;
  299.  
  300. } catch (SQLException e) {
  301. e.printStackTrace();
  302. }
  303. }
  304.  
  305. }
  306.  
  307. \\\\\\\\\\\\
  308.  
  309.  
  310. homee
  311.  
  312.  
  313. <!DOCTYPE html>
  314. <html>
  315. <head>
  316. <meta charset="ISO-8859-1">
  317. <title>Home Page</title>
  318. </head>
  319. <body>
  320. <h1 align="center">ILP Friends</h1>
  321.  
  322. <p align="center">
  323. <a href="Register.html">Add Friends</a>
  324. </p>
  325.  
  326. <p align="center">
  327. <a href="Search.html"> Search List</a>
  328. </p>
  329.  
  330. <p align="center">
  331. <a href="myServe?action=View"> Friend List</a>
  332. </p>
  333.  
  334. <br></br>
  335.  
  336. <h6 align="center">deepak.1@tcs.com</h6>
  337.  
  338. </body>
  339. </html>
  340.  
  341. \\\\\\\\\\\\\
  342.  
  343.  
  344. registerr
  345.  
  346.  
  347. <!DOCTYPE html>
  348. <html>
  349. <head>
  350. <meta charset="ISO-8859-1">
  351. <title>Registration Page</title>
  352. </head>
  353. <body>
  354. <h6 align="left">
  355. <a href="home.html">HOME</a>
  356. </h6>
  357. <h1 align="center">Friends Adding Form</h1>
  358. <div align=center>
  359. <form action="myServe" method="post">
  360.  
  361. <table>
  362.  
  363. <tr>
  364. <td>Full Name :</td>
  365. <td><input type="text" name="name" placeholder="Full Name" required maxlength=""></td>
  366. </tr>
  367.  
  368. <tr>
  369. <td>LG Number :</td>
  370. <td><input type="text" name="lg" placeholder="LG No."></td>
  371. </tr>
  372.  
  373. <tr>
  374. <td>Stream:</td>
  375. <td><input type="text" name="stream" placeholder="Stream"></td>
  376. </tr>
  377.  
  378. <tr>
  379. <td>Contact Number</td>
  380. <td><input type="text" name="contact" placeholder="Contact"></td>
  381. </tr>
  382. </table>
  383.  
  384. <br>
  385. <p align="center">
  386. <input type="submit" Value="SUBMIT">
  387. </p>
  388.  
  389. </form>
  390. </div>
  391. <br></br>
  392.  
  393. <h6 align="center">shahnawaz.md1@tcs.com</h6>
  394.  
  395. </body>
  396. </html>
  397.  
  398. \\\\\\\\\\
  399.  
  400.  
  401. searchh
  402.  
  403.  
  404.  
  405. <!DOCTYPE html>
  406. <html>
  407. <head>
  408. <meta charset="ISO-8859-1">
  409. <title>Search Page</title>
  410. </head>
  411. <body>
  412. <h6 align="left">
  413. <a href="home.html">HOME</a>
  414. </h6>
  415. <h1 align="center">Search Friend</h1>
  416. <div align=center>
  417. <form action="myServe?action=SEARCH" method="get">
  418. <table>
  419.  
  420. <tr>
  421. <td>Full Name :</td>
  422. <td><input type="text" name="name" placeholder="Full Name"></td>
  423. </tr>
  424. </table>
  425.  
  426. <br>
  427. <p align="center">
  428. <input type="submit" Value="SEARCH" name="action">
  429. </p>
  430.  
  431. </form>
  432.  
  433. <br></br>
  434.  
  435. <h6 align="center">deepak@tcs.com</h6>
  436. </body>
  437. </html>
  438.  
  439.  
  440. \\\\\\\\\\\
  441.  
  442.  
  443. view
  444.  
  445.  
  446.  
  447. <%@page import="com.bean.friends"%>
  448. <%@page import="java.util.ArrayList"%>
  449. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  450. pageEncoding="ISO-8859-1"%>
  451. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  452. <html>
  453. <head>
  454. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  455. <title>Insert title here</title>
  456. </head>
  457. <body>
  458.  
  459. <h6 align="left">
  460. <a href="Home.html">HOME</a>
  461. </h6>
  462. <h1 align="center">List Of Friends</h1>
  463.  
  464. <%
  465. ArrayList<friends> list = new ArrayList<>();
  466. list = (ArrayList<friends>) request.getAttribute("list");
  467. %>
  468.  
  469. <div align="center">
  470. <table border='1' width='5'>
  471. <tr>
  472. <th>Name</th>
  473. <th>L Group</th>
  474. <th>Stream</th>
  475. <th>contact</th>
  476. <th>Action</th>
  477. </tr>
  478.  
  479. <%
  480. for (friends f:list) {
  481. %>
  482.  
  483. <tr>
  484. <td><%=f.getName()%></td>
  485. <td><%=f.getLg()%></td>
  486. <td><%=f.getStream()%></td>
  487. <td><%=f.getContact()%></td>
  488. <td><a href="">Delete</a></td>
  489. </tr>
  490.  
  491. <%
  492. }
  493. %>
  494. </table>
  495. </div>
  496.  
  497. <br></br>
  498.  
  499. <h6 align="center">dkt@tcs.com</h6>
  500. </body>
  501. </html>
  502.  
  503.  
  504. \\\\\\\\
  505.  
  506. qwertry
  507.  
  508.  
  509. create table tbl_ilpfrnd(
  510. Name varchar(20),
  511. Lg int,
  512. Stream varchar(20),
  513. Contact int
  514. );
  515.  
  516. select * from tbl_ilpfrnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement