product.java

来自「续购物车」· Java 代码 · 共 54 行

JAVA
54
字号
package shopping.objectType;

import java.sql.*;
import java.io.*;

import shopping.connectionDB;

public class Product implements Serializable{
     private String productId;
     private String productName;
     private String productDesc;
     private Double productPrice;
     private connectionDB connectiondb=new connectionDB();
     private Statement statement;
     
     public void setProductId(String productId){
    	 this.productId=productId;
     }
     public String getProductId(){
    	 return productId;
     }
     public String getproductName(){
    	 return productName;
     }
     public String getproductDesc(){
    	 return productDesc;
     }
     public Double getProductPrice(){
    	 return productPrice;
     }
     public void getProductParameter(){
    	 try{
    	     statement=connectiondb.setDBConnection();
    	     String sql="select * from products where productid='"+productId+"'";
    	     ResultSet results=statement.executeQuery(sql);
    	     while(results.next())
    	     {
    	    	 productName=results.getString(2);
    	    	 productDesc=results.getString(3);
    	    	 productPrice=new Double(results.getInt(4));
    	     }
    	 }catch(Exception e)
    	 {
    		 System.out.println("get product informatio is error");
    	 }
     }
     public Product (String productId)
     {
    	 this.setProductId(productId);
    	 this.getProductParameter();
     }
     
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?