我正在使用下一个代码在标签中显示图像,当图片列为空时不对标签设置任何内容:
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);<p></p>
<pre><code> if(Passimg.length < 0){
PassLBL.settext("No Picture");
PassLBL.setIcon(null);
}
}
</code></pre>
<p>I've tried the next : </p>
<p>if(Passimg.equals(null)
{PassLBL.settext("No Picture");}</p>
<p>and tried</p>
if(Passimg == null)
{PassLBL.settext("No Picture"); }
但是没用!
最佳答案
当您从结果集中检索数据时
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);
}
我不太明白你需要什么,希望对你有帮助
关于java - 如何检查mysql中的blob列是否为null或为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38336683/