Calling java class in oracle procedure

i have one simple java program that prints 'hi' . i want to call that java program from pl/sql procedure.how to do that.

This is one method I am demonstrating.
SQL> CREATE or REPLACE AND COMPILE JAVA SOURCE NAMED "HiWorld" AS
  2  public class HiWorld {
  3 
  4   public static void MyMessage(String msg) {
  5    // TODO Auto-generated method stub
  6    System.out.println(msg);
  7    }
  8 
  9  }
10  /
Java created.
SQL> CREATE or replace PROCEDURE hi_world (p_command  IN  VARCHAR2)
  2  AS LANGUAGE JAVA
  3  NAME 'HiWorld.MyMessage(java.lang.String)';
  4  /
Procedure created.
SQL> BEGIN
  2    DBMS_JAVA.SET_OUTPUT(1000000);
  3    hi_world('Saubhik');
  4  End;
  5  /
PL/SQL procedure successfully completed.
SQL> set serverout on
SQL> /
Saubhik
Saubhik
PL/SQL procedure successfully completed.Another method is loading the class file with "loadjava" command. In that case first step "CREATE or REPLACE AND COMPILE JAVA SOURCE NAMED "HiWorld" AS" is not required.

Similar Messages

  • Calling java classes from plsql procedures

    I'm attempting to call java classes from plsql procedures which will create cmsdk users, folders, groups etc, however when I attempt to load a java class into the oracle schema using the command:
    loadjava -user user/password@database -resolve classname.class
    It generates error messages to the effect that classes (cmsdk classes) required by the class cannot be found. The class is loaded and marked with the status "invalid". Is it therefore necessary for me to load the cmsdk packages into the schema?
    Cheers
    David

    Using CMSDK Java API within the database has never been supported
    (see Problems loading IFS's java class into database
    When we needed to invoke CMSDK code from our PL/SQL code, we used one of two approaches:
    (1) use advanced queues to send requests to an external Java program (the CMSDK code, running outside the database) and receive the results back (asynchronous choice); or
    (2) make an HTTP request to a Java servlet (the CMSDK code, running in some Java web container like iAS) and get the response back in some custom format (XML or something) (synchronous choice).
    It seems to me that the CMSDK Java API was designed to be used only in middle-tier, not in database tier.
    Regards,
    Daniel.

  • How to call java class from pl/sql procedure ?

    Hello everyone,
    My query is..
    There is one pl/sql stored procedure which is doing some business logic and storing data in some columns of one table, suppose the table name is 'ABC' .. and the rest of columns of table ABC are getting updated using java class. Now my problem is whenever I insert data in ABC using store proc.. i have to call that java class so that it will update the rest columns ( why java class for updating the columns in ABC is ..because that logic cant be done from pl/sql proc.. it has to be done using java )
    and the other thing is.. oracle is in one machine and java is in another .. :(
    hope ..u can help me out !!
    Thank in advance !!

    but that updation have to be done from java code only.. we are using GIS tools .. have to create some shape files and update the column with that shape file.. so creation of shape file has to be done from java code only..
    so how to call java class file which is on another machine and oracle in another..

  • Calling Java programs from Oracle Stored Procedure

    Is it possible to call Java programs from Oracle stored procs? If possible Can this be used to exchange data from other applications? Is there a better method/feature in oracle for doing data exchange with other apps?

    If what you mean by Oracle stored procedures is pl/sql then yes.
    You can create a "wrapper" this way:
    CREATE OR REPLACE FUNCTION xmlXform
    in_mapUrl IN VARCHAR2,
    in_inputUrl IN VARCHAR2
    RETURN VARCHAR2
    AS
    LANGUAGE JAVA NAME
    'com.yourcompany.xml2any.xform(java.lang.String,java.lang.String)
    RETURN java.lang.String';
    Then load the java as:
    loadjava -user youruser/youruserpasswd -resolve -verbose lib/xmlparserv2.jar classes/com/yourcompany/xform.class classes/com/yourcompany/xml2any.class
    The java, given the correct permissions, can do anything java can do including communicate with outside applications.
    Is this the "best" way... depends on what you are trying to accomplish.

  • Calling Java Methods from Stored Procedures

    Can I call Java Methods from Oracle Stored Procedures? I have a Java framework that logs events and would like to reuse it for logging events that occur in stored procedures.
    null

    You need to publish java class methods to plsql.
    Attached below is some information.
    Although both PL/SQL modules and Java classes are stored in the database
    and are managed by many of the same mechanisms, each of them resides in
    its own namespace. Therefore, Java methods are not accessible from SQL
    and PL/SQL by default. In order to expose Java methods to the SQL and
    PL/SQL engines, first publish that Java method to the SQL namespace using
    a 'Call Spec'.
    Note: A 'Call Spec' does not create an additional layer of
    execution so there is no performance penalty incurred.
    A 'Call Spec' is simply a syntactical mechanism used to
    make a method known in the SQL namespace.
    The SQL name established by the 'Call Spec' can be top-level or packaged.
    The syntax differs only slightly and is consistent with that used for
    PL/SQL procedures and packages. For more information on the exact
    syntax, see the references listed in 'Related Topics'.
    In general, a top-level procedure 'Call Spec' takes the form:
    CREATE OR REPLACE PROCEDURE procname ( pname mode ptype, ... )
    AS LANGUAGE JAVA NAME 'javaname ( javatype, ... )';
    Where: procname is the SQL name you wish to publish
    pname is the name for a parameter to procname
    mode is the parameter mode (i.e. IN, OUT, IN OUT)
    ptype is a valid SQL type (e.g. NUMBER, CHAR, etc.)
    javaname is the fully qualified name of the Java method
    javatype is a Java type for the corresponding parameter
    Likewise, a top-level function 'Call Spec' takes the form:
    CREATE OR REPLACE FUNCTION fname ( pname mode ptype, ... ) RETURN rtype
    AS LANGUAGE JAVA NAME 'javaname ( javatype, ... ) return javatype';
    Where: fname is the SQL name you wish to publish
    rtype is the SQL return type of the function
    Note: Within the NAME clause, everything within quotes is case
    sensitive. For example, if the keyword 'return' is in all
    CAPS, this Call Spec will not compile.
    Other optional parts of this syntax have been omitted here for simplicity.
    Additional examples in subsequent sections illustrate some of these options.
    eg
    CREATE PROCEDURE MyProc (rowcnt IN NUMBER, numrows OUT NUMBER)
    AS LANGUAGE JAVA NAME 'MyClass.MyMethod(int, int[])';
    There are several important things to note here:
    1.) The 'Call Spec' for a JSP must be created in the same schema as the
    corresponding Java class that implements that method.
    2.) IN parameters are passed by value. This is the only parameter mode
    available in Java. OUT parameters, therefore, must be passed as single
    element arrays in order to emulate pass by reference.
    3.) Parameter names do not need to match, but the number and types of
    the parameters must match (with just one exception - see item 5 below).
    Oracle 8i supports conversions between an assortment of SQL and Java.
    See the references listed in 'Related Topics' for additional information.
    4.) Primitive types (e.g. int, float, etc.) are not required to be fully
    qualified with any package name. However, standard Java object types
    (e.g. String, Integer, etc.) as well as any user defined object types
    (e.g. like those generated by JPublisher) must be prefixed with a
    corresponding package name (e.g. java.lang) if applicable.
    5.) The 'main' method which takes a single String[] parameter can be
    mapped to any PL/SQL procedure or function which takes some number
    of VARCHAR2 or CHAR type IN parameters. For example, the java method:
    public static void main ( String[] args ) { ... }
    can be mapped to each of the following:
    PROCEDURE MyProc2 ( arg1 IN CHAR ) ...
    PROCEDURE MyProc3 ( arg1 IN CHAR, arg2 IN VARCHAR2 ) ...
    PROCEDURE MyProc4 ( arg1 IN VARCHAR2, arg2 IN VARCHAR2 ) ...
    and so forth. Parameters map to the corresponding element of the String
    array (e.g. arg1 -> args[0], arg2 -> args[1], etc.).
    null

  • Unable to get database connection  from loaded java class in oracle

    Hi all,
    I am trying to call java class method from oracle function, but getting below exception, while creating connection.
    SQL> select charge_calculation(1,'2011-06-01', 'E') from dual;
    select charge_calculation(1,'2011-06-01', 'E') from dual
    ERROR at line 1:
    ORA-29532: Java call terminated by uncaught Java exception:
    java.lang.ExceptionInInitializerError
    inside main method
    inside main method1
    inside main method2
    inside main method3
    inside main method3
    Exception in thread "Root Thread" java.lang.ExceptionInInitializerError
    at javax.crypto.Cipher.getInstance(DashoA12275)
    at oracle.security.o5logon.O5LoginClientHelper.decryptAES(Unknown Source
    at oracle.security.o5logon.O5LoginClientHelper.generateOAuthResponse(Unk
    nown
    Source)
    at
    oracle.jdbc.driver.T4CTTIoauthenticate.marshalOauth(T4CTTIoauthenticate.java)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:367)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:
    501)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:203)
    at
    oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java)
    at java.sql.DriverManager.getConnection(DriverManager.java)
    at java.sql.DriverManager.getConnection(DriverManager.java:187)
    at SPEodPricing.spEodPricing(SPEODPRICING:98)
    at SPEodPricing.main1(SPEODPRICING:47)
    Caused by: java.lang.SecurityException: Cannot set up certs for trusted CAs
    at javax.crypto.SunJCE_b.<clinit>(DashoA12275)
    ... 13 more
    Caused by: java.security.PrivilegedActionException: java.io.IOException
    at java.security.AccessController.doPrivileged(Native Method)
    ... 14 more
    Caused by: java.io.IOException
    at java.io.FileOutputStream.writeBytes(Native Method)
    at java.io.FileOutputStream.write(FileOutputStream.java)
    at sun.net.www.protocol.jar.URLJarFile$1.run(URLJarFile.java:177)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.jar.URLJarFile.retrieve(URLJarFile.java:165)
    at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:43)
    at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:70)
    at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.ja
    va:102)
    at
    sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:1
    24)
    at javax.crypto.SunJCE_d.a(DashoA12275)
    at javax.crypto.SunJCE_b.g(DashoA12275)
    at javax.crypto.SunJCE_b.e(DashoA12275)
    at javax.crypto.SunJCE_q.run(DashoA12275)
    ... 15 more
    SQL> select charge_calculation(1,'2011-06-01', 'E') from dual;
    select charge_calculation(1,'2011-06-01', 'E') from dual
    ERROR at line 1:
    ORA-29549: class BBVA_MERGED.SPEodPricing has changed, Java session state
    cleared
    SQL> exit
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64
    bit Production
    With the Partitioning, Real Application Clusters, OLAP, Data Mining
    and Real Application Testing options
    JAVA Sample code:-
    public String method1(int pi_ctry_id,String pi_cur_busi_date ,String pi_eod_bod_flag)
    System.out.println("inside main method1");
    CachedRowSet tmplcrs                = null;
    HashMap resMap                              = new HashMap();
              Double ln_candidate_extra           = 0.0;
              Double ln_calculate_on_val          = 0.0;
              int lv_calculate_on                = 0;
              int lv_cand_attribute                = 0;
    // int pi_ctry_id                          = 0;
    // String pi_cur_busi_date           = null;
    int pi_bch_id                          = 0;
    // String pi_eod_bod_flag               = null;
    Date ldt_cur_busi_date          = null;
    Date lstr_next_calc_date     = null;
    int li_bch_id                         = 0;
    int li_chg_ac_branch               = 0;
    int calFrequency                     = 0;
    DbUtils dbObj = new DbUtils();
    Map reqMap = new HashMap();
    CachedRowSet updtcrs                = null;
    Connection conn = null;
              try
    System.out.println("inside main method2");
                   reqMap.put("pi_ctry_id", ""+pi_ctry_id);
                   reqMap.put("pi_cur_busi_date", ""+pi_cur_busi_date);
                   reqMap.put("pi_eod_bod_flag", ""+pi_eod_bod_flag);
    System.out.println("inside main method3");
                   Class.forName("oracle.jdbc.driver.OracleDriver");
    // Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@10.1.56.85:1521:orcl", "bbva_merged", "bbva_merged");
    // conn = DriverManager.getConnection("jdbc:oracle:thin:@10.1.50.104:1521:cmsdb6", "bbva_base", "bbva_base");
    System.out.println("inside main method3");
    conn = DriverManager.getConnection("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.50.129)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.50.130)(PORT = 1521))(LOAD_BALANCE = yes)(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = BBVASIT)))", "BBVA_MERGED", "BBVA_MERGED");
    conn.setAutoCommit(false);
    System.out.println("inside main method4");
    }

    29532, 00000, "Java call terminated by uncaught Java exception: %s"
    // *Cause: A Java exception or error was signaled and could not be
    //          resolved by the Java code.
    // *Action: Modify Java code, if this behavior is not intended.

  • Run a java class in Oracle db to connect to Sybase

    Hi All, I'm looking for a way to connect to Sybase database at no-license-cost (meaning Oracle Gateway or similar 3rd party products), first coming idea was JDBC, I know I can run a java class in Oracle, the simple idea is to write a java class which connects to Sybase via JDBC thin driver and return the resultset of given query in a java class, the resultset will be presented in Oracle Apex framework.  Does anyone know if this can be done or not, and how?  Any howto articles are welcomed.
    Henry

    Henry:
    To connect to Sysbase or MsSQL Server you could use jTDS open source driver.
    http://sourceforge.net/projects/jtds/
    upload above driver (jar file) using loadjava, and grants the port connection using dbms_java.grant_permission procedure.
    Because jTDS is pure java driver (mode 4) is possible to use directly inside the RDBMS.
    Best regards, Marcelo.
    PD: Latest jtds driver is compiled against 1.6 sources, but oldest version will work with 1.5 for 11g.

  • How to call java class file from jsp

    hi
    we need to call java classes (which are written separately in .java file )from jsp file. we need it for our project if anyone knows about please reply us.
    bye
    siva sankari

    you can call the methods in a lot of ways. you could use scriptlets with the
    <%@ page import="package.class"%> and then inside instantiate an object
    <%
         MyClass mc = new MyClass(parameters if any);
         mc.theMethodYouWantToCall();
    %>or as Madathil has stated,
    or use the JSP tags
    <jsp:useBean id="anyname" class="classname"/>and then use the getProperty tag
    or even Custom Tags

  • Calling java class from jsp page

    Dear Friends.
    I wrote jsp page and java class.
    Am calling java class from jsp page. after processing result,
    I have to refresh jsp page from java class.
    processing time may take 5 minutes or 1 minute etc. that depends on user.
    Can It be possible ? if possible , How ?

    Ok, I get a very strange error now:
    org.apache.jasper.JasperException: Unable to compile class for JSPerror: An error has occurred in the compiler; please file a bug report (http://java.sun.com/cgi-bin/bugreport.cgi).
    What is this??? Anyone?

  • Java class in oracle apps forms

    java class in oracle apps forms
    We developed a java class and its running perfectly on local machine (Over the web through java applet ) But when we deployed it in apps and run with the client machine its not running .so please suggest where we put our java class files and how to run it in apps? Is there any API's .
    regards,
    krishna

    Hi user;
    What is your Client Operayting system, what is your browser?
    This error happens for one client or for all? Did you try to login from one other machine(for instance XP) and dif. browser version?
    Please check below which could be helpful for your issue:
    FRM-92101:
    Recommended Browsers for Oracle E-Business Suite Release 12 [ID 389422.1]
    FRM-92101: There Was a Failure in the Forms Server During Startup After Fresh R12 Installation [ID 429627.1]
    R12 fresh install FORMS DO NOT LAUNCH - FRM-92101/500 [ID 427714.1]
    FRM-92101: Forms Server oracle.forms.net.ConnectionException: Forms session <1> failed during startup: no response from runtime process [ID 880088.1]
    Also check:
    http://onlineappsdba.com/index.php/2009/06/15/frm-92101-with-internet-explorer-8-how-to-uninstall-ie8/
    Re: R12 database and JRE Issue
    Regard
    Helios

  • Calling java class from abap function moduile

    Is it possible to call java class from function module.
    i am a java guy. my need is to call a java class from a  function module in the backend. which in turn performs certain functions.
    i would be highly obliged if someone could let me know if this is possible.
    regards
    Srikumar V

    Hi Srikumar ,
    you can call a java webservice in ABAP .
    u can call the webservice and via that u can trigger the java class..
    Regards
    Renu

  • Call Java Class and Methods from ABAP

    Hi
    I install de JCo, But how i can call java class and methods from ABAP?. somebody has an example?
    The tutorial say that's is possible,  but don't explain how do that?
    Thanks.
    Angel G. Hurtado

    If you need only simple java program, you do not need to install JCo. The following codes can call java class.
    DATA: COMMAND TYPE STRING VALUE 'C:\j2sdk1.4.2_08\bin\java',
          DIR TYPE STRING VALUE D:\eclipse\workspace',
          PARAMETER TYPE STRING VALUE 'Helloworld'. "here the name of your java program
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
       EXPORTING
         APPLICATION = COMMAND
         PARAMETER = PARAMETER
         DEFAULT_DIRECTORY = DIR
       MAXIMIZED =
         MINIMIZED = 'X'     "If you need the DOS window to be minimized
      EXCEPTIONS
        CNTL_ERROR = 1
        ERROR_NO_GUI = 2
        BAD_PARAMETER = 3
        FILE_NOT_FOUND = 4
        PATH_NOT_FOUND = 5
        FILE_EXTENSION_UNKNOWN = 6
        ERROR_EXECUTE_FAILED = 7
        OTHERS = 8.
    Tell me if it works.
    Nuno.

  • Can anyone help i want to call java class using visual basic

    I want to call java class using visual basic and send some arguments to the main class

    Hi,
    I don't know VB, but you can surely launch a command line like :
    javaw.exe mypackage.MyMainClass myArgument1
    Regards

  • BAD CLASS FILE ERROR WHEN TRYING TO CALL JAVA CLASS IN WEB-INF DIRECTORY

    I AM NEW TO THIS FORUM. PLEASE HELP ME IDENTIFY/RESOLVE THIS ERROR - bad class file: /java/tomcat/webapps/ChoiceTel/WEB-INF/classes/XYZ/SMUA.class. OTHER JSP SCRIPTS THAT CALL JAVA CLASSES DO WORK WELL.
    THE FUNNY THING ABOUT COMPILIING THIS JAVA CLASS WAS - I HAD TO A jar xvf OF activation.jar and mail.jar IN THE XYZ DIRECTORY BEFORE SUCCESSFULLY COMPILING SMUA.
    THE CALL BEING MADE FROM THE JSP SCRIPT IS AS FOLLOWS:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
    <BODY>
    <%@ page import="XYZ.*" %>
    <%!
    %>
    <%
    SMUA sndmail = new SMUA();
    sndmail.postMail ("[email protected]","Test Subject","What Message","[email protected]");
    %>
    </BODY>
    </HTML>

    Dude. Please don't shout. If your keyboard is like mine, it can produce both upper and lower case letters. Please use them appropriately.
    Do you have the activation.jar/mail.jar available in the WEB-INF/lib directory for this application?

  • Call java class by using servlet

    i written simple servlet with doGet(0. I need call java class when i run servlet
    my requirement is when i start the server i will call servlet it will redirect to another page.
    but before that servlet will run java class. which i have written externally.
    i need to run java class by using servlet then it will redirect to another page.
    could you give the proper solution

    You don't call classes - you call methods.
    There's nothing special about servlets except the requirement that they implement HttpServlet. Servlets and other classes they interact with all get compiled into WEB-INF/classes on the server.
    To forward a request to, say, "other.jsp" you do:
    getServletContext().getRequestDispatcher("/other.jsp").forward(request,response);

Maybe you are looking for

  • Blue Screen on Domain controllers after Updates

    After patching our Domain controllers (virtual on ESXi 5.5 U2) recently we started getting Blue screens and reboots. Other changes in our environment around this time include enabling vshield drivers and scanning with Trend Micro. I have removed patc

  • Transferring Files On Hard Drive From PC To Mac:

    I have mp3s that aren't available anymore, and I still have them but they are stuck on an NTFS formatted hard drive. It is an internal hard drive not external, so I need desktops to get files off of it. Am I right that apple computers can only read f

  • Can you get rid of the alternative letters when typing a text message? Ie all the accented versions etc?

    I've just upgraded from and iPhone 3GS to the iPhone 5 and I'm finding it really slow to text because you have to wait for it to bring up all the options. Before it'll put the letter there. I don't have them on my iPad.

  • CS3 + ID CS4 - Color management Iussues in Bridge CS4

    I have CS3 WEB PREMIUM edition and recently added InDesign CS4. While trying to get the color management right for all Suite applications I get an error in Bridge CS4. "Suite Color Management is not enabled. Suite Color Management requires that a qua

  • Integration between Oracle BPM and Oracle UCM

    Hi I have a requirement how to integarte between Oracle BPM and Oracle UCM. Detailsabout the problem: Once user start the process and want to upload the document in the same process, the document should be uploaded into UCM and similarly user wants t