Omar Omar - 4 months ago 25
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" );
while(rset2.next()){
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);
PassLBL.setIcon(newPassImage);

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


I've tried the next :

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

and tried

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


but didn't work !

Answer

when you retrive the data from the resultSet

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

put if statement there

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

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