我正在尝试将存储在我的MySQL中的图片作为类型Blob上传,并将其他信息(如名称,价格描述和ID)上传到TableView- From SceneBuilder。这是我的Getters and Setters课程:
/*
* 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.
*/
package products;
import java.sql.Blob;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class showp {
public String id;
public String name;
public String price;
public Blob picture;
public String desc;
public showp(String id, String name, String price,Blob image, String desc){
this.id= id;
this.name= name;
this.price= price;
this.picture=image;
this.desc=desc;
}
//Getters
public String getId(){
return id;
}
public String getName(){
return name;
}
public String getPrice(){
return price;
}
public Blob getPicture(){
return picture;
}
public String getDesc(){
return desc;
}
//Setters
public void setId(String Id){
this.id=Id;
}
public void setName(String Name){
this.name=Name;
}
public void setPrice(String Price){
this.price=Price;
}
public void setPicture(Blob Picture){
this.picture=Picture;
}
public void setDesc(String Desc){
this.desc=Desc;
}
}
这是一个类,我在其中用数据填充表:
public void loadProducts() throws ClassNotFoundException{
try {
dc=new DbConncetion();
Connection conn= dc.Connect();
ol1=FXCollections.observableArrayList();
ol1.clear();
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM `products`");
while(rs.next()){
ol1.add(new showp(rs.getString(1),rs.getString(2),rs.getString(3), rs.getBlob(4) , rs.getString(5)));
}
pName.setCellValueFactory(new PropertyValueFactory<>("name"));
priceP.setCellValueFactory(new PropertyValueFactory<>("price"));
picP.setCellValueFactory(new PropertyValueFactory<>("image"));
pView.setItems(null);
pView.setItems(ol1);
} catch (SQLException ex) {
Logger.getLogger(Main1Controller.class.getName()).log(Level.SEVERE, null, ex);
}
}
我在这里和youtube上看到了很多例子,但我什么都不懂。任何人都可以解释我如何做到这一点。当我在我的表中执行该代码时,以这种格式com.mysql.jdbc.Blob@1b8f8da0
显示名称,价格和Blob列。我只想要而不是com.mysql.jdbc.Blob@1b8f8da0
来显示imageview中的真实图像或其他内容。提前致谢