Advertisement
Guest User

Untitled

a guest
Mar 8th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. <@page contentType="text/html" pageEncoding="UTF-8"%>
  2. <%@ page import ="java.sql.*" %>
  3. <% Class.forName("com.mysql.jdbc.Driver"); %>
  4. <% String idprod = request.getParameter("idprod");%>
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. <title>JSP Page</title>
  9. </head>
  10. <body>
  11. <%!
  12. public class Actor{
  13. String URL = "jdbc:mysql://localhost:3306/mysql";
  14. String USERNAME = "root";
  15. String PASSWD = "";
  16. String em="";
  17. String tempid="";
  18. Connection connection = null;
  19. PreparedStatement select= null;
  20. ResultSet resultSet = null;
  21. int a = 0;
  22. public Actor(String b){
  23. try{
  24. tempid=b;
  25. connection = DriverManager.getConnection(URL, USERNAME,PASSWD );
  26. select = connection.prepareStatement("SELECT quantity FROM products where id="+tempid );
  27. }
  28. catch (SQLException e){
  29. e.printStackTrace();
  30. }
  31. }
  32. public int check(){
  33. try{
  34. resultSet = select.executeQuery();
  35.  
  36. }
  37. catch (SQLException e){
  38. e.printStackTrace();
  39. }
  40. return a;
  41. }
  42. public String getActors(){
  43.  
  44. try{
  45. resultSet = select.executeQuery();
  46. while (resultSet.next()) {
  47. em = resultSet.getString("quantity");
  48. }
  49. } catch (SQLException e){
  50. e.printStackTrace();
  51. }
  52. return em;
  53. }
  54. }
  55. %>
  56. <%
  57.  
  58. Actor actor = new Actor(idprod);
  59. String actors = actor.getActors();
  60.  
  61. int iloscsztuk= Integer.parseInt(actors);
  62. int ilosckupionych =Integer.parseInt(request.getParameter("howmany"));
  63. int wynik=iloscsztuk-ilosckupionych;
  64.  
  65.  
  66.  
  67. Class.forName("com.mysql.jdbc.Driver");
  68. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql",
  69. "root", "");
  70. Statement st = con.createStatement();
  71. //ResultSet rs;
  72. int i = st.executeUpdate("Update products set quantity="+wynik);
  73. if (i > 0) {
  74. //session.setAttribute("userid", user);
  75. out.println("Kupiono "+ilosckupionych+" sztuk produktu.");
  76. %>
  77. <form method="POST" action="index.jsp">
  78. <input type = "submit" value = "Powrot" />
  79. </form>
  80.  
  81. <%
  82. } else {
  83. response.sendRedirect("index.jsp");
  84. }
  85.  
  86. %>
  87.  
  88. </body>
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement