I am getting the null pointer exception while setting the image to blob in db2 please help
below is my code
public class Myblob{ private Blob IMAGE_NAME= null;
@Column(name = "IMAGE_NAME")
public Blob getIMAGE_NAME() {
return this.IMAGE_NAME;
}
public void setIMAGE_NAME(Blob blob) {
this.IMAGE_NAME = blob;
}
)
for my controller code which is giving exception
File myfile=new File("D://wildfly//java//images//myimage.JPG");
BufferedImage originalImage=ImageIO.read(myfile);
ByteArrayOutputStream baos=new ByteArrayOutputStream();
ImageIO.write(originalImage, "jpg", baos );
byte[] imageInByte=baos.toByteArray();
Blob blob=null;
blob = (Blob) new SerialBlob(imageInByte );
System.out.println("the blob isss"+blob.toString());
if(blob==null){
System.out.println("blob is null");
} else {
System.out.println("blob is NOT null");
System.out.println(blob.length());
}
//at this line i am getting null but it is printing not null in sysout above
categoryMVO.setIMAGE_NAME(blob);
please suggest some answer
when iam trying to set the image to blob i am getting null pointer exception
can you verify that categoryMVO is not null ? otherwise can you post the exception please ? thx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.