Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /*CREATE TABLE Product(
- Order_num INTEGER,
- Customer_id INTEGER,
- Product_id INTEGER,
- Quality INTEGER,
- Shipping_cost INTEGER,
- Sales_date DATE(0001-01-01),
- Shipping_date DATE(0001-01-01),
- PRIMARY KEY(Product_id));
- */
- package com.myapp.struts;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import javax.faces.bean.ManagedBean;
- import javax.faces.bean.SessionScoped;
- /**
- *
- * @author
- */
- @ManagedBean(name = "product")
- @SessionScoped
- public class Product {
- private Integer orderNum;
- private Integer custID;
- private Integer prodID;
- private Integer quality;
- private Integer shippingCost;
- private String salesDate;
- private String shippingDate;
- public Product(Integer orderNum, Integer custID, Integer prodID, Integer quality, Integer shippingCost, String salesDate, String shippingDate) {
- this.orderNum = orderNum;
- this.custID = custID;
- this.prodID = prodID;
- this.quality = quality;
- this.shippingCost = shippingCost;
- this.salesDate = salesDate;
- this.shippingDate = shippingDate;
- }
- Product() {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- public Integer getOrderNum() {
- return orderNum;
- }
- public void setOrderNum(Integer orderNum) {
- this.orderNum = orderNum;
- }
- public Integer getCustID() {
- return custID;
- }
- public void setCustID(Integer custID) {
- this.custID = custID;
- }
- public Integer getProdID() {
- return prodID;
- }
- public void setProdID(Integer prodID) {
- this.prodID = prodID;
- }
- public Integer getQuality() {
- return quality;
- }
- public void setQuality(Integer quality) {
- this.quality = quality;
- }
- public Integer getShippingCost() {
- return shippingCost;
- }
- public void setShippingCost(Integer shippingCost) {
- this.shippingCost = shippingCost;
- }
- public String getSalesDate() {
- return salesDate;
- }
- public void setSalesDate(String salesDate) {
- this.salesDate = salesDate;
- }
- public String getShippingDate() {
- return shippingDate;
- }
- public void setShippingDate(String shippingDate) {
- this.shippingDate = shippingDate;
- }
- public String add() {
- String url = "jdbc:mysql://localhost:3306/mynewdatabase";
- String username = "root";
- String password = "nbuser";
- PreparedStatement ps = null;
- Connection con = null;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection(url, username, password);
- String sql = "INSERT INTO Product( Order_num, Customer_id, Product_id, Quality, Shipping_cost, Sales_date,"
- + "Shipping_date) VALUES(?,?,?,?,?,?,?)";
- ps = con.prepareStatement(sql);
- ps.setInt(1, orderNum);
- ps.setInt(2, custID);
- ps.setInt(3, prodID);
- ps.setInt(4, quality);
- ps.setInt(5, shippingCost);
- ps.setString(6,salesDate);
- ps.setString(7,shippingDate);
- ps.executeUpdate();
- System.out.println("Data Added Successfully");
- con.close();
- ps.close();
- return "response";
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- return "request";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement