JavaFX 8 Tutorial 49 - Image and Database
The code written in this tutorial is :
private FileInputStream fis;
Button button = new Button("Save");
button.setFont(Font.font("SanSerif", 15));
button.setOnAction(e ->{
try{
String query = "INSERT INTO UserDatabase ( Image) VALUES(?)";
pst = conn.prepareStatement(query);
fis = new FileInputStream(file);// file is selected using filechooser which is in last tutorial
pst.setBinaryStream(11, (InputStream)fis, (int)file.length());
pst.execute();
pst.close();
clearFields();
}catch(Exception e1){
label.setText("SQL Error");
System.err.println(e1);
}
});
Comments
Post a Comment