2016-04-19 9 views
0

AdminBussinessクラスからDTOに、次にDAOにデータを渡したいとします。クラスDTOとDAOの間のデータの受け渡し

私のデータは、AdminBussinessクラスからDAOまでずっと移動していません。

package com.diariofacil.business; 

import com.diariofacil.pojo.Product; 
import com.diariofacil.service.DiarioFacilException; 
import com.diariofacil.transferobject.ProductTO; 

/** 
* 
* @author asdrubal 
*/ 
public class AdminBussiness { 

public String product, description, code; 
public double price; 
public int productQuantity; 

Product productClass = new Product(); 

public AdminBussiness() { 
} 

public AdminBussiness(String product, double price, int productQuantity, String description, String code) { 
    this.product = product; 
    this.price = price; 
    this.productQuantity = productQuantity; 
    this.description = description; 
    this.code = code; 
} 

    /*gets and sets*/ 

public void addProduct(ProductTO productTO) throws DiarioFacilException{ 
    productClass.setNombre(this.getProduct()); 
    productClass.setPrice(this.getPrice()); 
    productClass.setMinimunStock(this.getProductQuantity()); 
    productClass.setDescription(this.getDescription()); 
    productClass.setCode(this.getCode()); 
    productTO.insert(productClass); 
} 

public void updateProduct(ProductTO productTO) throws DiarioFacilException, Exception { 
    productClass.setNombre(this.getProduct()); 
    productClass.setPrice(this.getPrice()); 
    productClass.setMinimunStock(this.getProductQuantity()); 
    productClass.setDescription(this.getDescription()); 
    productClass.setCode(this.getCode()); 
    productTO.update(productClass); 
} 

} 

addProductメソッドは追加ではありません。

package com.diariofacil.pojo; 

import com.diariofacil.interfaces.Soldable; 
import java.io.Serializable; 

public class Product extends Item implements Serializable, Soldable { 
    Provider provider; 
    Category category; 
    int minimunStock,id; 

    public Product(int id,Provider provider, Category category, int minimunStock, String nombre, String description, String code, double price) { 
    super(nombre, description, code, price); 
    this.provider = provider; 
    this.category = category; 
    this.minimunStock = minimunStock; 
} 

public Product(String nombre, String description, String code, double price) { 
    super(nombre, description, code, price); 
} 




public Product() { 
} 

public int getId() { 
    return id; 
} 

public void setId(int id) { 
    this.id = id; 
} 

public Provider getProvider() { 
    return provider; 
} 

public void setProvider(Provider provider) { 
    this.provider = provider; 
} 

public Category getCategory() { 
    return category; 
} 

public void setCategory(Category category) { 
    this.category = category; 
} 

public int getMinimunStock() { 
    return minimunStock; 
} 

public void setMinimunStock(int minimunStock) { 
    this.minimunStock = minimunStock; 
} 



} 

package com.diariofacil.transferobject; 

import com.diariofacil.pojo.*; 
import com.diariofacil.service.DiarioFacilException; 
import com.diariofacil.service.*; 
import java.io.Serializable; 
import java.util.List; 
import java.util.logging.Level; 
import java.util.logging.Logger; 

public class ProductTO implements Serializable{ 
    private ProductDAO dao = new ProductDAO(); 

public ProductTO() { 
} 

public void insert(Product product) throws DiarioFacilException { 
    dao.insert(product); 
}  
public void delete(Product product) throws DiarioFacilException{ 
     dao.delete(product); 
} 
public void update(Product product) throws DiarioFacilException, Exception{ 
    dao.update(product); 
} 


public List<Product> search() throws DiarioFacilException{ 
     return dao.SearchProduct(); 
    } 
} 

そしてDAO

package com.diariofacil.service; 

import com.diariofacil.pojo.*; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.util.ArrayList; 
import java.util.List; 

public class ProductDAO extends ServiceBase { 

private static final String INSERT = "INSERT INTO `product`(`id`,`price`,`description`," 
            + "`stock`,`category`,`seller` VALUES (?,?,?,?,?,?,?)"; 

private static final String DELETE ="DELETE FROM `diariofacil`.`product`\n" + 
            "WHERE ID VALUES (?);"; 
private static final String SELECT ="SELECT `product`.`id`,`product`.`name`"+ 
            "FROM `diariofacil`.`product`;"; 
private static final String UPDATE = "UPDATE product SET id = ?, price = ?, description = ?, category = ?, seller = ?, minimum_stock " 
             + "WHERE id = ?"; 


public void insert(Product product) throws DiarioFacilException { 
    this.connect(); 
    try { 
     PreparedStatement pstmt = this.getConexion().prepareStatement(INSERT); 

     pstmt.setInt(1, 1); 
     pstmt.setDouble(2, product.getPrice()); 
     pstmt.setString(3, product.getDescription()); 
     pstmt.setInt(4, product.getMinimunStock()); 
     pstmt.setObject(5, product.getCategory()); 
     pstmt.setObject(6, product.getProvider()); 


     pstmt.execute(); 

    } catch (SQLException ex) { 
     ex.printStackTrace(); 
     throw new DiarioFacilException("No se puedo insertar el registro."); 
    } finally { 
     this.disconect(); 
    } 
} 

public void update(Product product) throws Exception{ 
    this.connect(); 

    try { 
     PreparedStatement pstmt = this.getConexion().prepareStatement(UPDATE); 

     pstmt.setInt(1, product.getId()); 
     pstmt.setDouble(2, product.getPrice()); 
     pstmt.setString(3, product.getDescription()); 
     pstmt.setInt(4, product.getMinimunStock()); 

    } catch (SQLException ex) { 
     ex.printStackTrace(); 
     throw new Exception("No se pudo actualizar el registro"); 
    } finally { 
     this.disconect(); 
    } 
} 

public void delete(Product product) throws DiarioFacilException { 
    this.connect(); 

    try { 
     PreparedStatement pstmt = this.getConexion().prepareStatement(DELETE); 

     pstmt.setInt(1, product.getId()); 
     pstmt.executeUpdate(); 

    } catch (SQLException ex) { 
     ex.printStackTrace(); 
     throw new DiarioFacilException("No se puedo eliminar el registro."); 
    } finally { 
     this.disconect(); 
    } 

}

どのように私は、最初のクラスでaddProductメソッドでproductClassにproductToからデータを移動することができますか?

答えて

0

おそらくProductDAOの挿入クエリが正しくないですか?

VALUESの前に閉じ括弧 ")"を含めてはいけませんか?

関連する問題