Omar Omar - 1 year ago 95
SQL Question

how to check if blob column in mysql is null or empty

I'm using the next code to show image in label , to set nothing to label when picture column is null :

ResultSet rset2 = stmnt.executeQuery("select Picture from Pictures where Client_ID_pass =1" );
byte[] Passimg = rset2.getBytes("Picture");
//Resize The ImageIcon
ImageIcon Passimage = new ImageIcon(Passimg);
Image Passim = Passimage.getImage();
Image PassmyImg = Passim.getScaledInstance(PassLBL.getWidth(), PassLBL.getHeight(),Image.SCALE_SMOOTH);
ImageIcon newPassImage = new ImageIcon(PassmyImg);

if(Passimg.length < 0){
PassLBL.settext("No Picture");

I've tried the next :

{PassLBL.settext("No Picture");}

and tried

if(Passimg == null)
{PassLBL.settext("No Picture"); }

but didn't work !

Answer Source

when you retrive the data from the resultSet

 byte[] Passimg = rset2.getBytes("Picture");

put if statement there

if(passimg == null) {
   lable.setIcon(null);//to remove the old picture 
}else {
//show the image like you did before
 icon=create your icon here

i didn't undertand what you need exactly hope this help you

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download