📄 product.java
字号:
package shoppcart;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
public class Product {
private String ID;
private String productName;
private String publisher;
private String isbn;
private float price;
private String info;
private int type;
private String src;
private int count;
public Product(){ }
public Product(String id){
ConnectManager manager=null;
Connection con=null;
PreparedStatement st=null;
try{
manager=new ConnectManager();
con=manager.getConnection();
st=con.prepareStatement("select * from product where productID=?");
st.setInt(1,Integer.parseInt(id));
ResultSet rs=st.executeQuery();
while(rs.next()){
this.setID(rs.getString("productID"));
this.setName(rs.getString("productName"));
this.setPrice(Float.valueOf(rs.getString("productPrice")));
this.setPublisher(rs.getString("publisher"));
this.setCount(rs.getInt("leftCount"));
this.setSrc(rs.getString("productImg"));
this.setInfo(rs.getString("mainInfo"));
this.setType(rs.getInt("productType"));
}
}
catch(SQLException e){
e.printStackTrace();
}
finally{
if(st!=null){
try{
st.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
if(con!=null){
manager.close();
}
}
}
public String getID(){
return this.ID;
}
public String getName(){
return this.productName;
}
public String getPublisher(){
return this.publisher;
}
public String getIsbn(){
return this.isbn;
}
public float getPrice(){
return this.price;
}
public String getInfo(){
return this.info;
}
public int getType(){
return this.type;
}
public int getCount(){
return this.count;
}
public String getSrc(){
return this.src;
}
public void setID(String id){
this.ID=id;
}
public void setName(String name){
this.productName=name;
}
public void setSrc(String src){
this.src=src;
}
public void setPublisher(String publisher){
this.publisher=publisher;
}
public void setCount(int count){
this.count=count;
}
public void setType(int type){
this.type=type;
}
public void setPrice(float price){
this.price=price;
}
public void setIsbn(String Isbn){
this.isbn=Isbn;
}
public void setInfo(String Info){
this.info=Info;
}
public static List<Product> getProductList(String id){
ConnectManager manager=null;
Connection con=null;
PreparedStatement st=null;
try{
manager=new ConnectManager();
con=manager.getConnection();
st=con.prepareStatement("select * from product where productType=?");
st.setInt(1,Integer.parseInt(id));
ResultSet rs=st.executeQuery();
ArrayList<Product> list=new ArrayList<Product>();
while(rs.next()){
Product product=new Product();
product.setID(rs.getString("productID"));
product.setName(rs.getString("productName"));
product.setPrice(Float.valueOf(rs.getString("productPrice")));
product.setPublisher(rs.getString("publisher"));
product.setCount(rs.getInt("leftCount"));
product.setSrc(rs.getString("productImg"));
product.setInfo(rs.getString("mainInfo"));
product.setType(rs.getInt("productType"));
list.add(product);
}
return list;
}
catch(SQLException e){
e.printStackTrace();
return null;
}
finally{
if(st!=null){
try{
st.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
if(con!=null){
manager.close();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -