I am trying to save an image that is selected from a user interface using the following code:
private void botonSeleccionarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JFileChooser escogerArchivo = new JFileChooser();
if (escogerArchivo.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
archivo = escogerArchivo.getSelectedFile();
ImageIcon temporal = new ImageIcon(archivo.getAbsolutePath());
ImageIcon imagen = new ImageIcon(temporal.getImage().getScaledInstance(
this.etiquetaFoto.getWidth(),
this.etiquetaFoto.getHeight(),
Image.SCALE_DEFAULT));
this.etiquetaFoto.setIcon(imagen);
this.setArchivo(archivo);
}
}
Where at the end, I make a setArchivo (), so that the selected image is saved in a parameter of the class called file, of type File. The problem is that I do not find a reasonable way to store that file in SQL. In SQl I have a column called image of type image and I understand that it will be saved in byte format [], but how do I get the bytes of the selected file and how would I read the bytes of SQL to show it in the same interface? ?