Guest User

Untitled

a guest
Mar 14th, 2019
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.20 KB | None | 0 0
  1. package com.Controller;
  2.  
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5. import java.sql.SQLException;
  6.  
  7. import javax.servlet.RequestDispatcher;
  8. import javax.servlet.ServletException;
  9. import javax.servlet.annotation.WebServlet;
  10. import javax.servlet.http.HttpServlet;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13.  
  14. import com.bean.Grievance;
  15. import com.Service.ServiceClass;
  16.  
  17. @WebServlet("/MyServlet")
  18.  
  19. /**
  20. * Servlet implementation class MyServlet
  21. */
  22. public class MyServlet extends HttpServlet {
  23. private static final long serialVersionUID = 1L;
  24.  
  25. /**
  26. * @see HttpServlet#HttpServlet()
  27. */
  28. public MyServlet() {
  29. super();
  30. // TODO Auto-generated constructor stub
  31. }
  32.  
  33. /**
  34. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  35. * response)
  36. */
  37. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  38. throws ServletException, IOException {
  39. // TODO Auto-generated method stub
  40. response.getWriter().append("Served at: ").append(request.getContextPath());
  41. }
  42.  
  43. /**
  44. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  45. * response)
  46. */
  47. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  48. throws ServletException, IOException {
  49.  
  50. PrintWriter out = response.getWriter();
  51.  
  52. int grievance_Id = Integer.parseInt(request.getParameter("grievance_id"));
  53. String full_name = request.getParameter("full_Name");
  54. String address_Line1 = request.getParameter("address_1");
  55. String address_Line2 = request.getParameter("address_2");
  56. long contact_Number = Integer.parseInt(request.getParameter("contact"));
  57. int pincode = Integer.parseInt(request.getParameter("p_code"));
  58. String eMail = request.getParameter("mail");
  59. String complaint_type = request.getParameter("complaint");
  60. String complaint_description = request.getParameter("description");
  61. int wardNo = Integer.parseInt(request.getParameter("ward"));
  62.  
  63. Grievance gr = new Grievance(grievance_Id, full_name, address_Line1, address_Line2, contact_Number, pincode,
  64. complaint_type, complaint_description, eMail, wardNo);
  65.  
  66. ServiceClass service = new ServiceClass();
  67. int update = 0;
  68. try {
  69. update = service.insertDAO(gr);
  70. } catch (SQLException e) {
  71. e.printStackTrace();
  72. }
  73. System.out.println(update);
  74. if (update > 0) {
  75. out.print("<h1 align=center> Customer with Id " + gr.getGrievance_Id()+ " has been successfully inserted</h1>");
  76. } else {
  77. }
  78. }
  79. }
  80.  
  81.  
  82. ////////////////////
  83.  
  84.  
  85. package com.Service;
  86.  
  87. import java.sql.SQLException;
  88.  
  89. import com.bean.Grievance;
  90. import com.Dao.DAO;
  91.  
  92. public class ServiceClass {
  93. public int insertDAO(Grievance gr) throws SQLException{
  94. DAO insertDao = new DAO();
  95. return insertDao.insertDAO(gr);
  96. }
  97. }
  98.  
  99.  
  100.  
  101. //////////////////////
  102.  
  103.  
  104.  
  105.  
  106.  
  107. package com.Dao;
  108.  
  109. import java.sql.Connection;
  110. import java.sql.DriverManager;
  111. import java.sql.PreparedStatement;
  112. import java.sql.ResultSet;
  113. import java.sql.SQLException;
  114.  
  115. import com.bean.Grievance;
  116.  
  117. public class DAO {
  118. public int insertDAO(Grievance gr) throws SQLException{
  119. Connection connection = getConnection();
  120. String sql = "INSERT INTO tbl_grievance_1643044 VALUES (?,?,?,?,?,?,?,?,?,?)";
  121. PreparedStatement st = connection.prepareStatement(sql);
  122. st.setInt(1, gr.getGrievance_Id());
  123. st.setString(2, gr.getFull_name());
  124. st.setString(3, gr.getAddress_Line1());
  125. st.setString(4, gr.getAddress_Line2());
  126. st.setLong(5, gr.getContact_Number());
  127. st.setLong(6, gr.getPincode());
  128. st.setString(7, gr.geteMail());
  129. st.setString(8, gr.getComplaint_type());
  130. st.setString(9, gr.getComplaint_description());
  131. st.setInt(10, gr.getWardNo());
  132. int count = st.executeUpdate();
  133. return count;
  134. }
  135.  
  136. // public OrderData searchDAO(int OrderId) throws SQLException{
  137. // Connection connection = getConnection();
  138. // String sql = Select * From TBL_ORDER_1647274 where order_id = ?;
  139. // PreparedStatement st = connection.prepareStatement(sql);
  140. // st.setInt(1, OrderId);
  141. // ResultSet rs = st.executeQuery();
  142. // OrderData order = null;
  143. // while(rs.next()){
  144. // order = new OrderData(
  145. // rs.getInt(1),
  146. // rs.getString(2),
  147. // rs.getString(3),
  148. // rs.getLong(4),
  149. // rs.getString(5),
  150. // rs.getString(6));
  151. // }
  152. //
  153.  
  154. //
  155.  
  156. // return order;
  157. // }
  158. //
  159.  
  160. //
  161.  
  162. //
  163.  
  164. //
  165.  
  166. public Connection getConnection() throws SQLException{
  167. String url = "jdbc:oracle:thin:@INGNRGPILPHP01:1521:ORCLILP";
  168. String user = "aja170core";
  169. String password = "aja170core";
  170. try {
  171. Class.forName("oracle.jdbc.driver.OracleDriver");
  172. } catch (ClassNotFoundException e) {
  173. // TODO Auto-generated catch block
  174. e.printStackTrace();
  175. }
  176. Connection connection = DriverManager.getConnection(url, user, password);
  177. return connection;
  178. }
  179.  
  180.  
  181.  
  182. //////////////////
  183.  
  184.  
  185.  
  186. package com.util;
  187.  
  188. import java.sql.Connection;
  189. import java.sql.DriverManager;
  190. import java.sql.SQLException;
  191.  
  192. public class DbTransaction {
  193. private String url="jdbc:oracle:thin:@INGNRGPILPHP01:1521:ORCLILP";
  194. private String user="aja170core";
  195. private String password="aja170core";
  196. private Connection connection;
  197. private String tableName="tbl_grievance_1643044";
  198.  
  199. public String getTableName() {
  200. return tableName;
  201. }
  202.  
  203. public Connection getConnection() {
  204. try {
  205. closeConnection();
  206. Class.forName("oracle.jdbc.driver.OracleDriver");
  207. connection = DriverManager.getConnection(url, user, password);
  208.  
  209. } catch (SQLException e) {
  210. e.printStackTrace();
  211.  
  212. } catch (ClassNotFoundException e) {
  213.  
  214. e.printStackTrace();
  215. }
  216.  
  217. return connection;
  218. }
  219.  
  220. public void closeConnection() {
  221.  
  222. try {
  223. if (connection != null && connection.isClosed() == false)
  224. connection.close();
  225. connection = null;
  226.  
  227. } catch (SQLException e) {
  228. e.printStackTrace();
  229. }
  230. }
  231. }
  232.  
  233.  
  234.  
  235. ////////////////////
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242. <!DOCTYPE html>
  243. <html>
  244. <head>
  245. <meta charset="ISO-8859-1">
  246. <title>Insert title here</title>
  247. </head>
  248. <body>
  249. <h2 align="center">Registration Form</h2>
  250. <form action="MyServlet" method="post">
  251. <table align="center">
  252. <tr>
  253. <td>Grievance Id:</td>
  254. <td><input type="text" name="grievance_id"></td>
  255. </tr>
  256. <tr>
  257. <td>Full Name:</td>
  258. <td><input type="text" name="full_Name"></td>
  259. </tr>
  260.  
  261. <tr>
  262. <td>Address Line 1:</td>
  263. <td><input type="text" name="address_1"></td>
  264. </tr>
  265.  
  266. <tr>
  267. <td>Address Line 2:</td>
  268. <td><input type="text" name="address_2"></td>
  269. </tr>
  270.  
  271. <tr>
  272. <td>Contact:</td>
  273. <td><input type="text" name="contact"></td>
  274. </tr>
  275.  
  276. <tr>
  277. <td>Pin Code:</td>
  278. <td><input type="text" name="p_code"></td>
  279. </tr>
  280.  
  281. <tr>
  282. <td>Email Id:</td>
  283. <td><input type="text" name="mail"></td>
  284. </tr>
  285.  
  286. <tr>
  287. <td>Complaint Type:</td>
  288. <td><select required name="complaint">
  289. <option>-select-</option>
  290. <option>water related problems</option>
  291. <option>Birth/Death Certificate Related</option>
  292. <option>Repair of pot holes on road</option>
  293. <option>Application for new house drainage connection</option>
  294. <option>Request for action against unauthorized
  295. Construction of building</option>
  296. </select></td>
  297. </tr>
  298.  
  299. <tr>
  300. <td>Complaint Description:</td>
  301. <td><input type="text" name="description"></td>
  302. </tr>
  303.  
  304. <tr>
  305. <td>Ward Number:</td>
  306. <td><input type="text" name="ward"></td>
  307. </tr>
  308.  
  309. </table>
  310.  
  311. <br>
  312. <p align="center">
  313. <input type="submit" Value="SUBMIT">
  314. </p>
  315. </br>
  316. </form>
  317. </body>
  318. </html>
  319.  
  320.  
  321.  
  322. ///////////////
  323.  
  324.  
  325.  
  326.  
  327. package com.bean;
  328.  
  329. public class Grievance {
  330.  
  331. private int grievance_Id;
  332. private String full_name;
  333. private String address_Line1;
  334. private String address_Line2;
  335. private long Contact_Number;
  336. private long pincode;
  337. private String complaint_type;
  338. private String eMail;
  339. private String complaint_description;
  340. private int wardNo;
  341.  
  342. public Grievance(int grievance_Id,String full_name, String address_Line1, String address_Line2, long contact_Number, long pincode,
  343. String complaint_type, String complaint_description,String eMail, int wardNo) {
  344. super();
  345. this.grievance_Id= grievance_Id;
  346. this.eMail=eMail;
  347. this.full_name = full_name;
  348. this.address_Line1 = address_Line1;
  349. this.address_Line2 = address_Line2;
  350. Contact_Number = contact_Number;
  351. this.pincode = pincode;
  352. this.complaint_type = complaint_type;
  353. this.complaint_description = complaint_description;
  354. this.wardNo = wardNo;
  355. }
  356.  
  357. public int getGrievance_Id() {
  358. return grievance_Id;
  359. }
  360.  
  361. public void setGrievance_Id(int grievance_Id) {
  362. this.grievance_Id = grievance_Id;
  363. }
  364.  
  365. public String getFull_name() {
  366. return full_name;
  367. }
  368.  
  369. public void setFull_name(String full_name) {
  370. this.full_name = full_name;
  371. }
  372.  
  373. public String getAddress_Line1() {
  374. return address_Line1;
  375. }
  376.  
  377. public void setAddress_Line1(String address_Line1) {
  378. this.address_Line1 = address_Line1;
  379. }
  380.  
  381. public String getAddress_Line2() {
  382. return address_Line2;
  383. }
  384.  
  385. public void setAddress_Line2(String address_Line2) {
  386. this.address_Line2 = address_Line2;
  387. }
  388.  
  389. public long getContact_Number() {
  390. return Contact_Number;
  391. }
  392.  
  393. public void setContact_Number(long contact_Number) {
  394. Contact_Number = contact_Number;
  395. }
  396.  
  397. public long getPincode() {
  398. return pincode;
  399. }
  400.  
  401. public void setPincode(long pincode) {
  402. this.pincode = pincode;
  403. }
  404.  
  405. public String getComplaint_type() {
  406. return complaint_type;
  407. }
  408.  
  409. public void setComplaint_type(String complaint_type) {
  410. this.complaint_type = complaint_type;
  411. }
  412.  
  413. public String getComplaint_description() {
  414. return complaint_description;
  415. }
  416.  
  417. public void setComplaint_description(String complaint_description) {
  418. this.complaint_description = complaint_description;
  419. }
  420.  
  421. public int getWardNo() {
  422. return wardNo;
  423. }
  424.  
  425. public void setWardNo(int wardNo) {
  426. this.wardNo = wardNo;
  427. }
  428.  
  429. public String geteMail() {
  430. return eMail;
  431. }
  432.  
  433. public void seteMail(String eMail) {
  434. this.eMail = eMail;
  435. }
  436. }
Add Comment
Please, Sign In to add comment