0

I've the Apache common codecs library & I need to invoke that in the Oracle 11 database so I can create a java source that utilize the classes inside it as below.

What are the steps to make this library included in the database?

Java file needs to be included in Oracle DB

**Code need to achieved but giving symbol Can't be found

CREATE OR REPLACE JAVA SOURCE NAMED "org_apache_Base64" AS
import java.lang.*;
import java.sql.*;
import oracle.sql.*;
import java.io.*;
import javax.xml.bind.DatatypeConverter;
import org.apache.commons.codec.binary.Base64; 

public class org_apache_Base64
{
  public static void ExportBlob(String CONTFILE, BLOB CONTBLOB) throws Exception
  {
  try
  {
    File file = new File("/u01/oracle/jam_export/contract1");
    FileOutputStream fos = new FileOutputStream(file);  
    byte[] encodedBytes = Base64.getEncoder().encode("Test".getBytes());
    System.out.println("encodedBytes " + new String(encodedBytes));
    byte[] decodedBytes = Base64.getDecoder().decode(encodedBytes);
    System.out.println("decodedBytes " + new String(decodedBytes)); 
    System.out.println("PDF File Saved");
    fos.write(decoded); 
    fos.flush();
    fos.close(); 
    }
    catch  (Exception e) 
    {
     System.out.println(e); 
    }
  } };
MT0
  • 143,790
  • 11
  • 59
  • 117

1 Answers1

0

Find the jar files containing those dependencies (which is probably downloadable from Apache Commons Codec) and then use the loadjava utility to store them in the database so that Oracle can find them on its classpath.

loadjava -user USERNAME/PASSWORD@SID name_of_jar_file.jar

If you want to include the source files then you can also do that using loadjava but I would not recommend it for an external library as you would need to load ALL the dependencies for the Base64.java file and this may be hundreds (or thousands) of other source files; its easier just to find the JAR where these are packaged and load that one resource (or compile the source and package a JAR of it yourself).

MT0
  • 143,790
  • 11
  • 59
  • 117