java - 如何检查mysql中的blob列是否为null或为空

标签 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);<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/

相关文章:

java - Platform.runLater,处理大量任务太慢

mysql - 如何将图像从 Drupal 字段加载到 UIImageView?

c++ - 用C++和MySQL实现登录系统

java - 如何在HQL中选择group by LEFT(t.field, 6)?

java - 将接口(interface)方法委托(delegate)给各种类

java - 解析antlr3中的mixfix表达式

java - 对返回语句中未经检查的强制转换发出警告

php - 如何在 mysql 中确定 OR 条件的优先级

mysql - 如何在MySQL中创建也是主键的外键?

php - 填充表中的下拉菜单,然后从另一个表中设置所选选项