2 Replies Latest reply: Apr 6, 2011 5:05 AM by 850876 RSS

    How to use a Java Resource??

    850876
      Hello,

      I need to know how to use my external JAR I loaded in the database (hosted in Oracle 10.2.04) using this line below:

      CREATE OR REPLACE JAVA RESOURCE NAMED "MyJar" USING BFILE (BFILE_DIR,'MyExternal.jar');

      In fact, I have a Java file using this JAR, but I do not know how to tell to the java source that it have to use this JAR.

      ==========Java Source importing the Jar===================
      package com.gemalto.ws.snmp;

      import java.io.IOException;
      import java.util.Vector;

      import org.snmp4j.Snmp;
      import org.snmp4j.smi.*;
      import org.snmp4j.TransportMapping;
      import org.snmp4j.transport.DefaultUdpTransportMapping;
      import org.snmp4j.CommunityTarget;
      import org.snmp4j.mp.SnmpConstants;
      import org.snmp4j.PDU;
      import org.snmp4j.event.ResponseEvent;

      public class SNMPAgent
      {
      ......
      ==========================
      Could you give the SQL request or loadjava command line permitting to do use my java resource file?
      Thks
        • 1. Re: How to use a Java Resource??
          Yann39
          Hi,


          I think you should not load the jar as java resource.
          And I think there is no need to tell to the java source that it have to use the JAR. It will automatically look for the library.

          You should load the jar file using the loadjava utility.

          If it can helps, here is how I proceed :
          /* LOAD .JAR FILE */
          
          loadjava -user your_user/password@host -resolve -verbose -nodefiner C:\jdevstudio1013\jdev\lib\your_lib.jar
          
          /* LOAD PROGRAM */
          
          loadjava -user your_user/password@host -resolve -verbose -nodefiner C:\jdevstudio1013\jdev\mywork\your_program.java
          
          /* CREATE THE PL/SQL FUNCTION */
          
          create or replace procedure your_function(arg1 in varchar2, arg2 in varchar2) authid current_user as
          language java name 'your_program.your_function(java.lang.String, java.lang.String)';
          
          /* EXECUTE */
          
          select your_function('hello','world') from dual;
          • 2. Re: How to use a Java Resource??
            850876
            Thanks for your reply.
            However, I know about this loadjava utility and I want to avoid it because this method load each class of my jar!!

            If Oracle give the possiblity to create a java resource, normally we could use it instead of loading each class of the JAR file.

            Do you know another way to how use the resource?
            Thks.