8 How to Retrieve/Display Image from MySQL Database in java
Vložit
- čas přidán 8. 06. 2021
- I am showing an easy step in this video to get the image from the database into the label. just by creating one function and then a few lines, I write in the button section. You can also find the source code of this in the description you can copy the source code from my website.
My Website: softcoreproduction.com/
And you can't understand the concept, you can contact me or comment down below as soon as possible.
My Telegram: web.telegram.org/#/im?p=g5165...
My Instagram: / vishalmahor1899
Source code Function:
public class func{
public ResultSet find(String s){
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://sql6.freemysqlhosting.net:3306/sql6417047","sql6417047","HgyA61kd1y");
st = conn.prepareStatement("select * from details where name = ?");
st.setString(1, s);
rs = st.executeQuery();
} catch (ClassNotFoundException ex) {
Logger.getLogger(show_image.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(show_image.class.getName()).log(Level.SEVERE, null, ex);
}
return rs;
}
}
Source code Button Section:
try {
// TODO add your handling code here:
show_image.func f = new show_image.func();
rs = f.find(name.getText());
if(rs.next()){
byte[] img = rs.getBytes("image");
ImageIcon image = new ImageIcon(img);
Image im = image.getImage();
Image myimg = im.getScaledInstance(img1.getWidth(), img1.getHeight(), Image.SCALE_SMOOTH);
ImageIcon newImage = new ImageIcon(myimg);
img1.setIcon(newImage);
}
} catch (SQLException ex) {
Logger.getLogger(show_image.class.getName()).log(Level.SEVERE, null, ex);
}
All the source code is here hope it helps you.
#java #mysql #image
nice bhai good
What is the Code for 'initComoonent() in show_image() function ??
image stored in database as blob?
not as a blob, but in a blob. A blob is cloud storage.