Doubt when saving image in mysql database

Asked

Viewed 217 times

0

Good evening, here’s the deal: I have a Jlabel = jlImage, where an image is loaded as shown by the btnCaminhoImagemActionPerformed method.

But I want to use the save button to insert the image in the database, but I don’t know how to get the value of this jLabel which parameter should I pass in Preparedstatement? NOTE: The image is like longBlob in my base. Thanks for your cooperation.

 private void btnCaminhoImagemActionPerformed(java.awt.event.ActionEvent evt) {                                                 
             JFileChooser fc = new JFileChooser();
             fc.showOpenDialog(this);
             File f = fc.getSelectedFile();
             String path = f.getAbsolutePath();


             ImageIcon imagem = new ImageIcon(f.getAbsolutePath());

             Image imag = imagem.getImage().getScaledInstance(jlImagem.getWidth(), jlImagem.getHeight(), Image.SCALE_DEFAULT);

             jlImagem.setIcon(new ImageIcon(imag));

  }     




private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {                                          

   conexaoProdutos.conexao();

 PreparedStatement pst = conexaoProdutos.conn.prepareStatement("INSERT INTO produto (imagem) VALUES (?)");

        pst.set(1, );//O que usar como parâmetro?
        pst.execute();

    }                                        
  • Try the following:http://stackoverflow.com/a/19310279/5524514

  • Blz... Thank you...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.