JavaFX 8 Tutorial 50 - Retrive Image from Database
The code written in this tutorial is:
table.setOnMouseClicked(e ->{
try {
User user = (User)table.getSelectionModel().getSelectedItem();
String query = "select * from UserDatabase where ID = ?";
pst = conn.prepareStatement(query);
pst.setString(1, user.getID());
rs = pst.executeQuery();
while(rs.next()){
InputStream is = rs.getBinaryStream("Image");
OutputStream os = new FileOutputStream( new File("photo.jpg"));
byte[] content = new byte[1024];
int size = 0;
while((size = is.read(content)) != -1){
os.write(content, 0, size);
}
os.close();
is.close();
image = new Image("file:photo.jpg", 100, 150, true, true);
ImageView imageView1 = new ImageView(image);
imageView1.setFitWidth(100);
imageView1.setFitHeight(150);
imageView1.setPreserveRatio(true);
layout.setCenter(imageView1);
BorderPane.setAlignment(imageView1, Pos.TOP_LEFT);
}
pst.close();
rs.close();
} catch (SQLException ex) {
Logger.getLogger(Tutorial14.class.getName()).log(Level.SEVERE, null, ex);
} catch (FileNotFoundException ex) {
Logger.getLogger(Tutorial14.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Tutorial14.class.getName()).log(Level.SEVERE, null, ex);
}
});
still not showing my image
ReplyDeletelayout.setCenter(imageView1);what layout here mine is layout couldn't able to set it.
ReplyDelete