Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <@page contentType="text/html" pageEncoding="UTF-8"%>
- <%@ page import ="java.sql.*" %>
- <% Class.forName("com.mysql.jdbc.Driver"); %>
- <% String idprod = request.getParameter("idprod");%>
- <!DOCTYPE html>
- <html>
- <head>
- <title>JSP Page</title>
- </head>
- <body>
- <%!
- public class Actor{
- String URL = "jdbc:mysql://localhost:3306/mysql";
- String USERNAME = "root";
- String PASSWD = "";
- String em="";
- String tempid="";
- Connection connection = null;
- PreparedStatement select= null;
- ResultSet resultSet = null;
- int a = 0;
- public Actor(String b){
- try{
- tempid=b;
- connection = DriverManager.getConnection(URL, USERNAME,PASSWD );
- select = connection.prepareStatement("SELECT quantity FROM products where id="+tempid );
- }
- catch (SQLException e){
- e.printStackTrace();
- }
- }
- public int check(){
- try{
- resultSet = select.executeQuery();
- }
- catch (SQLException e){
- e.printStackTrace();
- }
- return a;
- }
- public String getActors(){
- try{
- resultSet = select.executeQuery();
- while (resultSet.next()) {
- em = resultSet.getString("quantity");
- }
- } catch (SQLException e){
- e.printStackTrace();
- }
- return em;
- }
- }
- %>
- <%
- Actor actor = new Actor(idprod);
- String actors = actor.getActors();
- int iloscsztuk= Integer.parseInt(actors);
- int ilosckupionych =Integer.parseInt(request.getParameter("howmany"));
- int wynik=iloscsztuk-ilosckupionych;
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql",
- "root", "");
- Statement st = con.createStatement();
- //ResultSet rs;
- int i = st.executeUpdate("Update products set quantity="+wynik);
- if (i > 0) {
- //session.setAttribute("userid", user);
- out.println("Kupiono "+ilosckupionych+" sztuk produktu.");
- %>
- <form method="POST" action="index.jsp">
- <input type = "submit" value = "Powrot" />
- </form>
- <%
- } else {
- response.sendRedirect("index.jsp");
- }
- %>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement