I am getting the following error upon executing Oracle Java procedure that accepts and returns BLOB data,
Error report - ORA-00932: inconsistent datatypes: expected a return value that is an instance of a user-defined Java class convertible to an Oracle type got an object that could not be converted ORA-06512: at "", line 86 ORA-06512: at line 7 00932. 00000 - "inconsistent datatypes: expected %s got %s" *Cause:
*Action:
Java Code
public static java.sql.Blob Convert_Image(java.sql.Blob srcBlob) {
java.sql.Blob desBlob = null;
try {
Document document = new Document();
ByteArrayOutputStream pdfDocumentOutputStream = new ByteArrayOutputStream();
PdfWriter pdfDocumentWriter = PdfWriter.getInstance(document, pdfDocumentOutputStream);
document.open();
if (document.newPage()) {
int indentation = 0;
Image img = Image.getInstance(srcBlob.getBytes(1, (int) srcBlob.length()));
float scaler = document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin() - indentation;
img.scalePercent((scaler / img.getWidth()) * 100);
document.newPage();
document.add(Image.getInstance(img));
document.close();
desBlob = new SerialBlob(pdfDocumentOutputStream.toByteArray());
pdfDocumentWriter.close();
pdfDocumentOutputStream.close();
}
}
catch (Exception e) {
Show_Message(e);
}
return desBlob;
}
Oracle Code
FUNCTION CONVERT_IMAGE(
P_BLOB IN DOCUMENTS.BLOB_CONTENT%TYPE)
RETURN BLOB
AS
LANGUAGE JAVA NAME 'egift.Util.Convert_Image (java.sql.Blob) return java.sql.Blob';
Trigger Implementation
...
DECLARE
v_blob_content DOCUMENTS.BLOB_CONTENT%TYPE;
BEGIN
IF :NEW.BLOB_CONTENT IS NOT NULL AND
(
NVL(:NEW.MIME_TYPE,'#') = 'image/png' OR
NVL(:NEW.MIME_TYPE,'#') = 'image/jpeg' OR
NVL(:NEW.MIME_TYPE,'#') = 'image/gif' OR
NVL(:NEW.MIME_TYPE,'#') = 'image/tiff' OR
NVL(:NEW.MIME_TYPE,'#') = 'image/bmp'
) THEN
v_blob_content := EGIFT_UTIL.CONVERT_IMAGE(:NEW.BLOB_CONTENT);
IF v_blob_content is not null then
:NEW.BLOB_CONTENT := v_blob_content;
:NEW.MIME_TYPE := 'application/pdf';
:NEW.NAME := substr(:NEW.NAME,0,instr(:NEW.NAME,'.',-1)) || 'pdf';
END IF;
END IF;
...
Blobis you're just going to use a byte array anyway. Use a byte array. - Andreas