Passing a blob parameter as a parameter in a java method using Oracle JVM

Hey, I'm trying to find a way to achieve this. I am using oracle 10g database where I have drops stored in a table. I want to read and pass blob to java method in my java code. I loaded my java class into my database via loadjava. The table in which my drops are stored is also set up.

This is my java class and the method I would like to pass BLOB

import java.lang.*;
import java.sql.*;
import oracle.sql.*;

public class Test
{

  public static void getWidth(BLOB myBlob) throws Exception
  {
    System.out.println(myblob.length());
  }

};

And this is my Java stored procedure (Wrapper) in PL / SQL

CREATE OR REPLACE PROCEDURE testmethod (p_blob  IN  BLOB)
AS LANGUAGE JAVA   
NAME 'Test.getWidth(oracle.sql.BLOB)';

It loads the java class into the database, and my shell compiles and is also saved.

When I want to run execute testmethod(testphoto.jpg);

this gives me an error: 'testphoto.jpg must be declared'

Any recommendations for this? Thank you for your time.

This is my PL / SQL BLock from my testmethod:

DECLARE  
  P_FILE VARCHAR2(200);  
  P_BLOB BLOB;  
BEGIN  
  P_FILE := NULL;  
  P_BLOB := NULL;  

  TESTMETHOD(  
    P_FILE => P_FILE,  
    P_BLOB => P_BLOB  
  );  
END;
+3
source share
1

testphoto.jpg - , . blob . blob , . .

, , :

create table blobtest (filecontents blob);
insert into blobtest values (utl_raw.cast_to_raw('Test Data'));

pl/sql sqlplus, :

declare
  temp blob;
  filename varchar2(200) := 'Test';
begin

  select filecontents
    into temp
    from blobtest;

  testmethod(filename, temp);

end;
/

, blob, dbms_lob getLength :

select dbms_lob.getLength(filecontents) from blobtest;

+3

Source: https://habr.com/ru/post/1787450/


All Articles