Picture of the interfaceI am trying to display an image from database (search by bookId) into the interface, which needs to put into jLabel.
There's nothing wrong with the code, there's no error that is showing But it still doesn't work
So far this is my code
import java.sql.*;
import javax.swing.*;
Connection conn;
Statement stmt;
ResultSet rs;
String query;
PreparedStatement statement;
ImageIcon format;
Object image
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
try{
query="select Abstract from books where BookId= 2020010001";
statement = conn.prepareStatement(query);
rs= statement.executeQuery();
if(rs.next()){
byte[]imagedata=rs.getBytes("Abstract");
format = new ImageIcon(imagedata);
jLabel3.setIcon(format);
}
}
catch(SQLException e){
JOptionPane.showMessageDialog(this,"connection error 1");
}
// TODO add your handling code here:
}
}
I've change some codes and this is the code.
//the code for the button
String f = "select Abstract from books where BookId= 2020010001";
try{
PreparedStatement preparedstatement;
preparedstatement = conn.prepareStatement(f);
rs= preparedstatement.executeQuery();
jLabel3.setIcon(new ImageIcon(f));
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(this,"connection error 1");
}
This time it shows error
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException