Reputation: 11
I have read about storing image in database isn't practical, so I stored the image path in Mysql database. How can I display the image in my program? Whenever I tried to set the icon of JLabel, an error said "cannot converted string to icon. What can I do?
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/jose", "root", "josehaha");
Statement stat = (Statement) con.createStatement();
stat.executeQuery("select img_path from product where ID = 1;");
ResultSet rs = stat.getResultSet();
Object path = rs.getString("img_path");
jLabel1.setIcon("'" + path + "'");
} catch (ClassNotFoundException | SQLException e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
Upvotes: 1
Views: 30