如何检查mysql中的blob列是null还是空

时间:2016-07-12 18:46:05

标签: java mysql

我正在使用下一个代码在标签中显示图片,在图片列为空时不设置任何标签:

  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"); }

但没有用!

1 个答案:

答案 0 :(得分:1)

从resultSet

中检索数据时
 byte[] Passimg = rset2.getBytes("Picture");

将if语句放在那里

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);
}

我没有承诺你需要什么,希望这能帮到你