I have an Image (type: java.awt.Image) in memory, I want to convert it to a Blob (type: java.sql.Blob) using jdk 1.7.
Everything I've been able to find on this subject uses streams and files. Surely I don't need to save this Image to a file before being able to convert it??
Not much to show here, but an example follows:
import java.sql.Blob; import java.awt.Image;
public GenericResponseType savePhoto(Image image)
{
Connection conn = ds.getConnection();
<< some DB code and assembly of PreparedStatement >>
Blob blob = conn.createBlob();
<< here's where the magic needs to happen I need to get the image parameter to blob >>
// I've tried the following but doesn't quite work as it wants a RenderedImage
// OutputStream os = blob.setBinaryStream(1);
// ImageIO.write(parameters.getPhoto().getImage(), "jpg", os);
pstmt.setBlob(4, blob);
}
Some more detail (though I doubt it matters much) is that the above is generated using web services/JAX-WS from WSDL with an operation declared using MTOM. So it generates a signature with an Image being passed as a variable.