Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Controller;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.sql.SQLException;
- 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.bean.Grievance;
- import com.Service.ServiceClass;
- @WebServlet("/MyServlet")
- /**
- * Servlet implementation class MyServlet
- */
- public class MyServlet extends HttpServlet {
- private static final long serialVersionUID = 1L;
- /**
- * @see HttpServlet#HttpServlet()
- */
- public MyServlet() {
- 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 {
- PrintWriter out = response.getWriter();
- int grievance_Id = Integer.parseInt(request.getParameter("grievance_id"));
- String full_name = request.getParameter("full_Name");
- String address_Line1 = request.getParameter("address_1");
- String address_Line2 = request.getParameter("address_2");
- long contact_Number = Integer.parseInt(request.getParameter("contact"));
- int pincode = Integer.parseInt(request.getParameter("p_code"));
- String eMail = request.getParameter("mail");
- String complaint_type = request.getParameter("complaint");
- String complaint_description = request.getParameter("description");
- int wardNo = Integer.parseInt(request.getParameter("ward"));
- Grievance gr = new Grievance(grievance_Id, full_name, address_Line1, address_Line2, contact_Number, pincode,
- complaint_type, complaint_description, eMail, wardNo);
- ServiceClass service = new ServiceClass();
- int update = 0;
- try {
- update = service.insertDAO(gr);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- System.out.println(update);
- if (update > 0) {
- out.print("<h1 align=center> Customer with Id " + gr.getGrievance_Id()+ " has been successfully inserted</h1>");
- } else {
- }
- }
- }
- ////////////////////
- package com.Service;
- import java.sql.SQLException;
- import com.bean.Grievance;
- import com.Dao.DAO;
- public class ServiceClass {
- public int insertDAO(Grievance gr) throws SQLException{
- DAO insertDao = new DAO();
- return insertDao.insertDAO(gr);
- }
- }
- //////////////////////
- package com.Dao;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import com.bean.Grievance;
- public class DAO {
- public int insertDAO(Grievance gr) throws SQLException{
- Connection connection = getConnection();
- String sql = "INSERT INTO tbl_grievance_1643044 VALUES (?,?,?,?,?,?,?,?,?,?)";
- PreparedStatement st = connection.prepareStatement(sql);
- st.setInt(1, gr.getGrievance_Id());
- st.setString(2, gr.getFull_name());
- st.setString(3, gr.getAddress_Line1());
- st.setString(4, gr.getAddress_Line2());
- st.setLong(5, gr.getContact_Number());
- st.setLong(6, gr.getPincode());
- st.setString(7, gr.geteMail());
- st.setString(8, gr.getComplaint_type());
- st.setString(9, gr.getComplaint_description());
- st.setInt(10, gr.getWardNo());
- int count = st.executeUpdate();
- return count;
- }
- // public OrderData searchDAO(int OrderId) throws SQLException{
- // Connection connection = getConnection();
- // String sql = Select * From TBL_ORDER_1647274 where order_id = ?;
- // PreparedStatement st = connection.prepareStatement(sql);
- // st.setInt(1, OrderId);
- // ResultSet rs = st.executeQuery();
- // OrderData order = null;
- // while(rs.next()){
- // order = new OrderData(
- // rs.getInt(1),
- // rs.getString(2),
- // rs.getString(3),
- // rs.getLong(4),
- // rs.getString(5),
- // rs.getString(6));
- // }
- //
- //
- // return order;
- // }
- //
- //
- //
- //
- public Connection getConnection() throws SQLException{
- String url = "jdbc:oracle:thin:@INGNRGPILPHP01:1521:ORCLILP";
- String user = "aja170core";
- String password = "aja170core";
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- Connection connection = DriverManager.getConnection(url, user, password);
- return connection;
- }
- //////////////////
- 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_grievance_1643044";
- 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();
- }
- }
- }
- ////////////////////
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <h2 align="center">Registration Form</h2>
- <form action="MyServlet" method="post">
- <table align="center">
- <tr>
- <td>Grievance Id:</td>
- <td><input type="text" name="grievance_id"></td>
- </tr>
- <tr>
- <td>Full Name:</td>
- <td><input type="text" name="full_Name"></td>
- </tr>
- <tr>
- <td>Address Line 1:</td>
- <td><input type="text" name="address_1"></td>
- </tr>
- <tr>
- <td>Address Line 2:</td>
- <td><input type="text" name="address_2"></td>
- </tr>
- <tr>
- <td>Contact:</td>
- <td><input type="text" name="contact"></td>
- </tr>
- <tr>
- <td>Pin Code:</td>
- <td><input type="text" name="p_code"></td>
- </tr>
- <tr>
- <td>Email Id:</td>
- <td><input type="text" name="mail"></td>
- </tr>
- <tr>
- <td>Complaint Type:</td>
- <td><select required name="complaint">
- <option>-select-</option>
- <option>water related problems</option>
- <option>Birth/Death Certificate Related</option>
- <option>Repair of pot holes on road</option>
- <option>Application for new house drainage connection</option>
- <option>Request for action against unauthorized
- Construction of building</option>
- </select></td>
- </tr>
- <tr>
- <td>Complaint Description:</td>
- <td><input type="text" name="description"></td>
- </tr>
- <tr>
- <td>Ward Number:</td>
- <td><input type="text" name="ward"></td>
- </tr>
- </table>
- <br>
- <p align="center">
- <input type="submit" Value="SUBMIT">
- </p>
- </br>
- </form>
- </body>
- </html>
- ///////////////
- package com.bean;
- public class Grievance {
- private int grievance_Id;
- private String full_name;
- private String address_Line1;
- private String address_Line2;
- private long Contact_Number;
- private long pincode;
- private String complaint_type;
- private String eMail;
- private String complaint_description;
- private int wardNo;
- public Grievance(int grievance_Id,String full_name, String address_Line1, String address_Line2, long contact_Number, long pincode,
- String complaint_type, String complaint_description,String eMail, int wardNo) {
- super();
- this.grievance_Id= grievance_Id;
- this.eMail=eMail;
- this.full_name = full_name;
- this.address_Line1 = address_Line1;
- this.address_Line2 = address_Line2;
- Contact_Number = contact_Number;
- this.pincode = pincode;
- this.complaint_type = complaint_type;
- this.complaint_description = complaint_description;
- this.wardNo = wardNo;
- }
- public int getGrievance_Id() {
- return grievance_Id;
- }
- public void setGrievance_Id(int grievance_Id) {
- this.grievance_Id = grievance_Id;
- }
- public String getFull_name() {
- return full_name;
- }
- public void setFull_name(String full_name) {
- this.full_name = full_name;
- }
- public String getAddress_Line1() {
- return address_Line1;
- }
- public void setAddress_Line1(String address_Line1) {
- this.address_Line1 = address_Line1;
- }
- public String getAddress_Line2() {
- return address_Line2;
- }
- public void setAddress_Line2(String address_Line2) {
- this.address_Line2 = address_Line2;
- }
- public long getContact_Number() {
- return Contact_Number;
- }
- public void setContact_Number(long contact_Number) {
- Contact_Number = contact_Number;
- }
- public long getPincode() {
- return pincode;
- }
- public void setPincode(long pincode) {
- this.pincode = pincode;
- }
- public String getComplaint_type() {
- return complaint_type;
- }
- public void setComplaint_type(String complaint_type) {
- this.complaint_type = complaint_type;
- }
- public String getComplaint_description() {
- return complaint_description;
- }
- public void setComplaint_description(String complaint_description) {
- this.complaint_description = complaint_description;
- }
- public int getWardNo() {
- return wardNo;
- }
- public void setWardNo(int wardNo) {
- this.wardNo = wardNo;
- }
- public String geteMail() {
- return eMail;
- }
- public void seteMail(String eMail) {
- this.eMail = eMail;
- }
- }
Add Comment
Please, Sign In to add comment