In this tutorial you will be able to store image in SQL server database using Java
Please watch the video because there are some task to be done beside code
Code to Store Image in SQL Server using Java Netbeans
private void btnImageActionPerformed(java.awt.event.ActionEvent evt) {// TODO add your handling code here:
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
filename = f.getAbsolutePath();
ImageIcon imageIcon = new ImageIcon(new ImageIcon(filename).getImage().getScaledInstance(lbl_img.getWidth(),lbl_img.getHeight(),Image.SCALE_SMOOTH));
lbl_img.setIcon(imageIcon);
try{
File image = new File(filename);
FileInputStream fis = new FileInputStream(image);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf= new byte[1024];
for(int readNum;(readNum=fis.read(buf))!=-1;){
bos.write(buf,0,readNum);
}
person_image=bos.toByteArray();
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
Please don't forget To Like, Share and Subscribe my Youtube video and Channel.
Youtube Channel Subscription Click Here
No comments:
Post a Comment