Guest User

Untitled

a guest
Feb 12th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5.  
  6. package testing;
  7. import java.io.*;
  8. import java.sql.*;
  9. import javax.servlet.*;
  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. /**
  16. *
  17. * @author Admin
  18. */
  19.  
  20. public class regdbservlet extends HttpServlet {
  21. /* private static String algorithm = "DESede";
  22. private static Key key = null;
  23. private static Cipher cipher = null;
  24.  
  25. private static byte[] encrypt(String input)throws Exception {
  26. cipher.init(Cipher.ENCRYPT_MODE, key);
  27. byte[] inputBytes = input.getBytes();
  28. return cipher.doFinal(inputBytes);
  29. }
  30. */
  31. /**
  32. * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
  33. * @param request servlet request
  34. * @param response servlet response
  35. * @throws ServletException if a servlet-specific error occurs
  36. * @throws IOException if an I/O error occurs
  37. */
  38. protected void processRequest(HttpServletRequest request, HttpServletResponse res)
  39. throws ServletException, IOException {
  40. /* key = KeyGenerator.getInstance(algorithm).generateKey();
  41. cipher = Cipher.getInstance(algorithm);
  42.  
  43. response.setContentType("text/html;charset=UTF-8");*/
  44. PrintWriter out = res.getWriter();
  45. String firstname=request.getParameter("firstname");
  46. String surname=request.getParameter("surname");
  47. String email=request.getParameter("email");
  48. String zipcode=request.getParameter("zipcode");
  49. String userId=request.getParameter("userId");
  50. String dealer_password=request.getParameter("dealer_password");
  51. String town=request.getParameter("town");
  52. String country=request.getParameter("country");
  53. //String input = dealer_password;
  54. //byte[] encryptionBytes = encrypt(input);
  55. //String passw=new String(encryptionBytes);
  56. String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=swingmail";
  57. String user = "sa";
  58. String pwd = "sa";
  59.  
  60. Connection con=null;
  61. // Statement st=null;
  62. //ResultSet rs=null;
  63. try {
  64. Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
  65. con = DriverManager.getConnection(url,user,pwd);
  66. //String sql = "INSERT INTO memory VALUES ('" + surname + "','" + firstname + "'," + userId + ","+ zipcode +",'"+ email +"','"+ dealer_password +"','"+ town +"','"+ country +"')" ;
  67. String sql = "insert into Dealer_Register values (?,?,?,?,?,?,?,?)";
  68. PreparedStatement ps =con.prepareStatement(sql);
  69. ps.setString(1, surname);
  70. ps.setString(2, firstname);
  71. ps.setString(3, userId);
  72. ps.setString(4, zipcode);
  73. ps.setString(5, email);
  74. ps.setString(6, dealer_password);
  75. ps.setString(7, town);
  76. ps.setString(8, country);
  77. out.println("<html>");
  78. out.println("<head>");
  79. out.println("<title>Servlet regdbservlet</title>");
  80. out.println("</head>");
  81. out.println("<body>");
  82. out.println("<h1>Servlet regdbservlet at " + request.getContextPath () + "</h1>");
  83. out.println("</body>");
  84. out.println("</html>");
  85.  
  86. }
  87. catch(Exception cnfe){
  88. cnfe.printStackTrace();
  89. }
  90. finally {
  91. out.close();
  92. }
  93. }
  94. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  95. /**
  96. * Handles the HTTP <code>GET</code> method.
  97. * @param request servlet request
  98. * @param response servlet response
  99. * @throws ServletException if a servlet-specific error occurs
  100. * @throws IOException if an I/O error occurs
  101. */
  102. @Override
  103. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  104. throws ServletException, IOException {
  105. processRequest(request, response);
  106.  
  107. }
  108.  
  109. /**
  110. * Handles the HTTP <code>POST</code> method.
  111. * @param request servlet request
  112. * @param response servlet response
  113. * @throws ServletException if a servlet-specific error occurs
  114. * @throws IOException if an I/O error occurs
  115. */
  116. @Override
  117. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  118. throws ServletException, IOException {
  119.  
  120. processRequest(request, response);
  121.  
  122. }
  123.  
  124. /**
  125. * Returns a short description of the servlet.
  126. * @return a String containing servlet description
  127. */
  128. @Override
  129. public String getServletInfo() {
  130. return "Short description";
  131. }// </editor-fold>
  132.  
  133. }
  134.  
  135. ps.executeUpdate();
  136.  
  137. con.commit();
  138.  
  139. insert into Dealer_Register (id, foo, bar, baz, ...) values (?,?,?,?,?,?,?,?)
Add Comment
Please, Sign In to add comment