我正在尝试使用javafx从mysql数据库检索图像。图像使用长blob存储在数据库中。执行此操作时会出现垃圾值。这是用于从数据库检索图像的代码。
JFXTreeTableColumn<Property,String> propertyImage = new JFXTreeTableColumn<>("Image");
propertyImage.setPrefWidth(100);
propertyImage.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Property, String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<Property, String> param) {
return param.getValue().getValue().propertyImage;
}
});
属性视图
数据库连接
public class Property extends RecursiveTreeObject<Property>{
StringProperty propertyId;
StringProperty address;
StringProperty state;
StringProperty zipCode;
StringProperty price;
StringProperty bedNum;
StringProperty bathNum;
StringProperty propertyImage;
StringProperty propertyType;
StringProperty propertyStatus;
StringProperty squareFeet;
StringProperty parkingSpot;
StringProperty agent_id;
public Property(){
super();
}
public Property(String propertyId, String address, String state, String zipCode, String price, String bedNum, String bathNum, String propertyImage, String propertyType, String propertyStatus, String squareFeet, String parkingSpot, String agent_id) {
this.propertyId = new SimpleStringProperty(propertyId);
this.address = new SimpleStringProperty(address);
this.state = new SimpleStringProperty(state);
this.zipCode = new SimpleStringProperty(zipCode);
this.price = new SimpleStringProperty(price);
this.bedNum = new SimpleStringProperty(bedNum);
this.bathNum = new SimpleStringProperty(bathNum);
this.propertyImage = new SimpleStringProperty(propertyImage);
this.propertyType = new SimpleStringProperty(propertyType);
this.propertyStatus = new SimpleStringProperty(propertyStatus);
this.squareFeet = new SimpleStringProperty(squareFeet);
this.parkingSpot = new SimpleStringProperty(parkingSpot);
this.agent_id = new SimpleStringProperty(agent_id);
}
}
db连接
ObservableList<Property> properties = FXCollections.observableArrayList();
Connection connection = DBConnection.getConnection();
try {
PreparedStatement ps = (PreparedStatement)connection.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while(rs.next()){
properties.add(new Property(rs.getInt(1)+"",rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getString(9),rs.getString(10),rs.getString(11),rs.getString(12),rs.getString(13)));
}
} catch (SQLException ex) {
Logger.getLogger(SearchSalePropertyController.class.getName()).log(Level.SEVERE, null, ex);
}
1条答案
按热度按时间ufj5ltwl1#
最后,您发布了数据库访问的代码。当您从数据库获取数据时,您已经做错了
ResultSet
.当然,
Property.propertyImage
也应改为ObjectProperty<Image>
. 同样,该列也应改为JFXTreeTableColumn<Property, Image>
.