Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将BuffereImage转换为图像数据类型_Java_Mysql_Imageview_Blob_Bufferedimage - Fatal编程技术网

Java 将BuffereImage转换为图像数据类型

Java 将BuffereImage转换为图像数据类型,java,mysql,imageview,blob,bufferedimage,Java,Mysql,Imageview,Blob,Bufferedimage,我试图从数据库表中检索blob数据类型,并在imageView中显示图像。以下是我的select SQL语句: public boolean retrieve(){ boolean success = false; ResultSet rs = null; DBController db = new DBController(); db.getConnection(); String dbQuery = "SELECT * FROM sm_product WHERE produc

我试图从数据库表中检索blob数据类型,并在imageView中显示图像。以下是我的select SQL语句:

public boolean retrieve(){
boolean success = false;
ResultSet rs = null;
DBController db = new DBController();   
db.getConnection();     
String dbQuery = "SELECT * FROM sm_product WHERE productName ='" + name +"'";       
rs = db.readRequest(dbQuery);
try {
    if(rs.next()){
        desc = rs.getString("productDescription");
        price = rs.getInt("productPrice");
        quantity = rs.getInt("productQuantity");
        dateStr = rs.getString("dateOfCreation");
                    category = rs.getString("productCategory");     

                   Blob blob = rs.getBlob("productImage");
                   byte[] data = blob.getBytes(0, (int) blob.length());
                   image = ImageIO.read(new ByteArrayInputStream(data)); //Error here
                    success = true;
    }   
}
catch(Exception e){
    e.printStackTrace();
}   
db.terminate();
return success;
}
检索后,我想在imageview中显示它。代码如下:

panel.getMyImageView().setImage(product.getImage());
但是,我收到了不兼容的类型错误消息。我知道image=ImageIO.read(newbytearrayinputstream(data));这一行应该存储为BuffereImage,然后从那里我慢慢地转换为image数据类型并显示在image view中。但是经过两个小时的研究,我没有得到任何运气。谁能帮我一下吗

提前谢谢

Toolkit.getDefaultToolkit().createImage(data)
对从blob读取的字节数组调用此函数