Advertisement
BorislavaYordanova

Hat

May 1st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. package ClothingItemShop;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.Statement;
  7.  
  8. public class Hat extends ClothingItemShop {
  9.  
  10.     private static float box_price;
  11.  
  12.     public Hat(float price_param, float weight_param, String color_param, String colorPattern_param, String size_param,
  13.             String fabric_param) {
  14.         super(price_param, weight_param, color_param, colorPattern_param, size_param, fabric_param);
  15.     }
  16.  
  17.     static {
  18.         try {
  19.             Connection connection = null;
  20.             Statement statement = null;
  21.  
  22.             Class.forName("com.mysql.jdbc.Driver");
  23.             connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/clothingitem", "root", "123456");
  24.  
  25.             statement = connection.createStatement();
  26.             ResultSet result = statement.executeQuery("SELECT container_price FROM containers WHERE item_type = 'Hat'");
  27.  
  28.             while (result.next()) {
  29.                 box_price = result.getFloat("container_price");
  30.                 System.out.println("The box price for the Hat is: " + box_price);
  31.             }
  32.             result.close();
  33.             statement.close();
  34.             connection.close();
  35.         } catch (Exception e) {
  36.             System.out.print(e);
  37.         }
  38.     }
  39.  
  40.     public float getContainerPrice() {
  41.         return box_price;
  42.     }
  43.  
  44.     public float getItemPrice() {
  45.         return price;
  46.     }
  47.  
  48.     public float getWeight() {
  49.         return weight;
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement