Call EJB From Oracle Stored proc or Database loaded Java?

Are there any examples of calling an EJB, residing in the OC4J on a machine separate from the DB server,
from an Oracle PL/SQL stored proc.
The Stored proc can call java loaded into the DB. That java makes the intial bean context. Or another way if suggested.
The reason is that I need to use some drivers that I have so far been unable to load directly into the DB using
loadjava util. I plan on using the driver in the EJB, located on a different machine. But I'd like so know if its possible to
make the IntialContext call to the EJB container from PL/SQL. Are the OC4J drivers loadable to be
able to be called from a database loaded java class? ( I might be a little off on my terminology)
Bob
[email protected]

Hi Bob,
Your question has been previously asked on this forum many times already.
You can probably find the relevant postings by doing a search of the
forum archives.
To summarize those posts, as I understand it, the latest version of OC4J
(version 9.0.3) contains a "oc4jclient.jar" file (I think that's the name
of the file), that can be loaded into the Oracle database (using the
"loadjava" utility), and which allows a java stored procedure to invoke
methods on an EJB residing in OC4J.
Please note that I have not tried any of the above -- I am only summarizing
for you what has already been posted. And like I said before, a search
of the forum archives will probably give you more details.
Good Luck,
Avi.

Similar Messages

  • How to SEND PAGE from Oracle stored proc

    I've searched all Oracle docs and internet. Need to be able to
    send a msg to a pager via SMS (or some other method) from a
    stored proc. Saw some mention of Oracle Paging Server but not
    much doc on implementing. Please feel free to post here or
    mailto:[email protected]

    if you need to send sms message you need to have wapgateway and
    wml background

  • Calling EJB from Oracle via IIOP

    I've spent the last two days trying to figure out how I can call an
    EJB from an Oracle Stored Procedure. I first looked into WLS JNDI
    (Using WLInitialContextFactory ), but my collegue recommended I look
    into IIOP because it is "less proprietary". I was able to get a WL
    example working that does a lookup on an EJB and "narrows" the IIOP
    object...so it looked promissing, but then I tried to load the JAR
    into Oracle and it said:
    "referenced name javax/rmi/PortableRemoteObject could not be found"
    So I did a quick check and it looks like this didn't come into
    existance until JDK 1.3. By all accounts, Oracle 8.1.6 supports JDK 2
    (1.2). So now I'm stuck. I've got a few examples about connecting to
    the Oracle ORB using session-iiop, but I don't know if Weblogic will
    be able to work with this. I don't know how I'd even call it because
    the URL requires an Oracle SID...so now what? I see three options.
    Please let me know which would be best (or another option that I'm
    missing)
    1. Try connecting with Weblogic "T3"
    2. Try to get the right combination of classes loaded so 1.2 can work
    like 1.3
    3. Use the Oracle IIOP (I have no examples for connecting to other
    ORBs so I have no idea how to lookup objects).
    Chris

    [email protected] (Chris Snyder) writes:
    Andy Piper <[email protected]> wrote in message news:<[email protected]>...
    [email protected] (Chris Snyder) writes:
    1. Try connecting with Weblogic "T3"It depends on what version of WLS you are using. If you are using 6.1
    then you are out-of-luck because this only support JDK 1.3.1.We are using WLS 6.1 and Oracle 8.1.6. There's got to be a way to
    connect what is essentially a 1.2 JVM to a 1.3.1 JVM. On my way home
    yesterday I was wondering if just straight RMI would work...although
    we need to encrypt the connection. I've seen several people talk
    about calling EJB's from stored procedures so it seems like there is a
    way. Any other ideas?The really gross way is HTTP. In a previous life I had a customer use
    oracle's HTTP plug-in to do this. You could probably invert the
    problem also. I.e. write CORBA objects that sit inside an Orb hosted
    in WLS and invoke on those using oracle's CORBA support. But HTTP is
    probably the way most likely to work. You probably couldn't use RMI
    over HTTP either - you would have to write a servlet that delegated to
    your beans.
    andy

  • Return String from Oracle stored proc using Excel 2003 VBA

    Hi to everyone,
    I've got a problem that remains unsolved for many days. I am trying to return a value of an oracle stored procedure using Excel VBA. It might seem trivial, however it's not for someone, who has never done it before...
    OS: Win XP SP3
    Excel 2003
    Ora Client: 11g
    By trying different things I have noticed, that I could have troubles with the ODBC-connection. Maybe I am not using the right one. To store data returned from select statements I have an ODBC-Connection (Driver: Oracle in XE), which works perfectly, e.g.:
    Sub Extract_Data()
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim db_name, UserName, Password As String
    cn.Open db_name, USerName, Password
    sql_statement = "SELECT some_text FROM some_table"
    Set rs = cn.Execute(sql_statement)
    rs.MoveFirst 'jump to the first entry in the data list
    Row = 2
    While Not rs.EOF
    'save the data to a worksheet
    ip.Cells(Row, 2) = rs(0).Value
    Row = Row + 1
    rs.MoveNext
    Wend
    End Sub
    Now I need to execute a stored procedure to return a semi-colon delimited string.
    I have tried the following:
    Public Sub obj_class()
    Dim cn As New ADODB.Connection
    Dim strSQL, cn As String
    Dim adoCMD As ADODB.Command
    Dim adoRS As ADODB.Recordset
    Set wb = Excel.ActiveWorkbook
    Set ih = wb.Sheets("InfoSheet")
    cn.Open db_name, UserName, Password
    Set adoCMD = New ADODB.Command
    With adoCMD
    .ActiveConnection = cn
    .CommandText = "S#mdb$stg_da_extr_util.get_all_classes_of_classif"
    .CommandType = adCmdStoredProc
    .Parameters.Refresh
    '------ and here comes the error saying:
    '------ could not find the object in the collection corresponding to the name or ordinal reference requested by the application
    .Parameters("i_caller").Value = "'STG_DATA_REQUEST'"
    .Parameters("i_obj_classif_id").Value = 120
    Set adoRS = .Execute()
    End With
    End Sub
    I did asked on the forum:
    http://www.access-programmers.co.uk/forums/showthread.php?p=1241667#post1241667
    but unfortunately without success.
    Could it be, that my ODBC-connection is wrong? When debugging the connection string, I find the Provider=MSDASQL5.1.
    I have moderate knowledge in VBA, but absolutely a newbie with Oracle DB. Is there any source of information that can help solving this issue? Looking forward to hearing from you, as I am almost giving up... ;(

    My VBA is super rusty. Does that error come after Parameters.Refresh, or after .Parameters("i_caller").Value = "'STG_DATA_REQUEST'"?
    If it's the second one, you'll need the definition of the stored procedure so you can see what parameters it's expecting. That'd mean you're getting something wrong with the names.

  • 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.

  • Error calling BLS from oracle database

    Hi Experts,
    We have a scenario in which we are calling BLS from oracle database using trigger. The call is made using the following URL:
    http://<Host name>:50000/XMII/Runner?Transaction=<TRX_Path>&Material=MATNR&Pallet_id=PALLET&Plant=PLANT&Proc_order=PROC&Prodline=PROD&Quantity=QTY&Start_Date=DAT&Start_Time=TIM&Status=STAT&UOM=UOM1&User_name=USER&OutputParameter=*
    This used to work fine in 11.5 but when we upgraded to 14.0 it is not working. We have maintained server details in \etc\host file.
    We were getting error in file 'Error 1 Text.txt'. "A possible Cross-Frame Scripting attack has been prevented. Please contact your system administrator or refer to" this was the last error message. We checked this on SCN and based on the search results we have implemented SAP note 1651004 wherein setting in netweaver is required to be changed. After note was implemented we are getting another error text ('Error 2 Text.txt') "This will happen if the browser running the page tha". We tried a few ways but could not capture the full message coming.
    Has anybody of faced similar problem? I would highly appreciate any hint which could help in solving this problem.
    System Information:
    NW 7.31 SP 10
    Oracle 11.2.0.4
    MII 14.0 SP5 patch 7
    Regards,
    Darshan

    Hi Christian/Anushree,
    I have now modified the URL by adding Illum login name and password:
    http://<Host name>:50000/XMII/Runner?Transaction=<TRX_Path>&Material=MATNR&Pallet_id=PALLET&Plant=PLANT&Proc_order=PROC&…
    When i run the url in browser it gives me the expected results but when i try to trigger it from Oracle i am still getting the error as below:
    "<script>
      var inPortalScript = false
      var webpath = "/logon_ui_resources/"
    </script>
    <html>
    <head>
    <BASE target="_self">
    <link rel=stylesheet href="/logon_ui_resources/css/ur/ur_ie5.css">
    <title>User Management, SAP AG</title>
    <script language="javascript">
    var originWindowName=window.name;
    window.name="logonAppPage";
    function restoreWindow() {
    try{
    window.name=originWindowName;
    } catch(ex){}
    </script>
    <script language="JavaScript">
    function putFocus(formInst, elementInst) {
      if (document.forms.length > 0) {
        document.forms[formInst].elements[elementInst].focus();
    function setValuesAutoCreation() {
    var form = document.getElementById('logonForm');
    form.j_username.value="";
    form.j_password.value="";
    form.automaticAccountCreation.value="true";
    function submitForm() {
    var form = document.getElementById('logonForm');
    form.submit();
    function clearEntries() {
      document.logonForm.longUid.value="";
      document.logonForm.password.value="";
    function setFocusToFirstField() {
    myform = document.logonForm;
    try{
       for (i=0; i<myform.length; i++) {
        elem = myform.elements[i];
        if (!elem.disabled) {
          elemType = elem.type;
          if (elemType=="text" || elemType=="password") {
           if (!elem.readOnly) {
              elem.focus();
              break;
          if (elemType=="select-one" || elemType=="select-multiple" || elemType=="checkbox" || elemType=="radio") {
            elem.focus();
            break;
    } catch(ex){
    function addTenantPrefix() {
      return true;
    </script>
    </head>
    <body class="urBdyStd" bgcolor="#F7F9FB" onLoad="setFocusToFirstField()" onUnload="restoreWindow()">
    Thanks,
    Darshan
    <script language="JavaScript">
    var blockPage = false;
    </script>
    <script language="JavaScript">
    try {
      if (top.document.domain != self.document.domain) {
      blockPage = true;
    } catch (error) {
      // This will happen if the browser running the page tha"

  • Calling EJB from Java Stored Procedures

    Hi,
    I am trying to call an Enterprise Java Bean from stored procedure. This stored procedure calls a java program. As long as it is a simple java program it works fine and loadjava.exe does not give any problem (neither compile-time nor run-time).
    It is not working when I am trying to call EJB from it. It is giving compile-time error.
    If anybody has implemented the same please suggest how to go forward.
    thanks in advance,
    Shashank Agarwal

    I tried the same thing without any luck. I assume you are using OC4J for your EJB ...
    The compiling issue may be because you don't have the classes in your EJB client jar loaded into the database. Once those classes are loaded, you should loadjava without any problem.
    However, you won't be able to call the EJB server because the EJB client (your Java code in the DB) will need the OC4J environment (oc4j.jar). I have tried to load oc4j.jar into the DB as well, and that was a big mess and nothing worked. My DB is 8.1.7, maybe the new 9i have OC4J libs bundled?!?
    I looked around and only found 2 alternatives:
    1. Write a JSP page that acts like an EJB client, then use URLConnection in your DB java code to send params to the JSP for it to invlode the EJB
    2. Replace the JSP with RMI code, and use RMI instead of URLConnection in your DB code to invloke the EJB client.
    If you find any other solution, please share it here.
    Good luck!
    Hi,
    I am trying to call an Enterprise Java Bean from stored procedure. This stored procedure calls a java program. As long as it is a simple java program it works fine and loadjava.exe does not give any problem (neither compile-time nor run-time).
    It is not working when I am trying to call EJB from it. It is giving compile-time error.
    If anybody has implemented the same please suggest how to go forward.
    thanks in advance,
    Shashank Agarwal

  • Calling OLE API from Oracle Stored Procedure

    An application that I need to intergate with exposes only the OLE API. How can I invoke these OLE APIs from Oracle stored procedure? Do I need any special/ additional Oracle components? Can you please help. Any links to examples would be very helpful. Thanks.

    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.

  • How to generate a report in pdf from a stored proc

    Hi, i need guidance on how to generate a report in pdf from an oracle stored proc.
    The environment is oracle 10gas + 10gdb.
    On a specific event, a PL/SQL stored procedure is called to do some processing and at the end of the processing to generate report which has to be sent to the printer (and optionally previewed by the user).
    Can anyone assist me with this?

    Hi ,
    One 'simple' way is by using the DBMS_SCHEDULER db package and the procedure CREATE_JOB(....) using as job_type the value 'EXECUTABLE'...
    Read for further info in 'PL/SQL Packages and Types Reference'.
    If you have access to OEM ... you can configure this there using wizard.....
    Other way is to use the External Procedure call capabiblity of Oracle DB Server...:
    http://www.oracle.com/pls/db102/ranked?word=external+procedure+call&remark=federated_search
    My greetings,
    Sim

  • Problem Obtaining multiple results from MySql Stored Proc via JDBC

    I've spent alot of time on this and I'd be really grateful for anyones help please!
    I have written a java class to execute a MySQL stored procedure that does an UPDATE and then a SELECT. I want to handle the resultset from the SELECT AND get a count of the number of rows updated by the UPDATE. Even though several rows get updated by the stored proc, getUpdateCount() returns zero.
    It's like following the UPDATE with a SELECT causes the updatecount info to be lost. I tried it in reverse: SELECT first and UPDATE last and it works properly. I can get the resultset and the updatecount.
    My Stored Procedure:
    delimiter $$ CREATE PROCEDURE multiRS( IN drugId int, IN drugPrice decimal(8,2) ) BEGIN UPDATE drugs SET DRUG_PRICE = drugPrice WHERE DRUG_ID > drugId; SELECT DRUG_ID, DRUG_NAME, DRUG_PRICE FROM Drugs where DRUG_ID > 7 ORDER BY DRUG_ID ASC; END $$
    In my program (below) callablestatement.execute() returns TRUE even though the first thing I do in my stored proc is an UPDATE not a SELECT. Is this at odds with the JDBC 2 API? Shouldn't it return false since the first "result" returned is NOT a resultset but an updatecount? Does JDBC return any resultsets first by default, even if INSERTS, UPDATES happened in the stored proc before the SELECTs??
    Excerpt of my Java Class:
    // Create CallableStatement CallableStatement cs = con.prepareCall("CALL multiRS(?,?)"); // Register input parameters ........ // Execute the Stored Proc boolean getResultSetNow = cs.execute(); int updateCount = -1; System.out.println("getResultSetNow: " +getResultSetNow); while (true) { if (getResultSetNow) { ResultSet rs = cs.getResultSet(); while (rs.next()) { // fully process result set before calling getMoreResults() again! System.out.println(rs.getInt("DRUG_ID") +", "+rs.getString("DRUG_NAME") +", "+rs.getBigDecimal("DRUG_PRICE")); } rs.close(); } else { updateCount = cs.getUpdateCount(); if (updateCount != -1) { // it's a valid update count System.out.println("Reporting an update count of " +updateCount); } } if ((!getResultSetNow) && (updateCount == -1)) break; // done with loop, finished all the returns getResultSetNow = cs.getMoreResults(); }
    The output of running the program at command line:
    getResultSetNow: true 28, Apple, 127.00 35, Orange, 127.00 36, Bananna, 127.00 37, Berry, 127.00 Reporting an update count of 0
    During my testing I have noticed:
    1. According to the Java documentation execute() returns true if the first result is a ResultSet object; false if the first result is an update count or there is no result. In my java class callablestatement.execute() will return TRUE if in the stored proc the UPDATE is done first and then the SELECT last or vica versa.
    2. My java class (above) is coded to loop through all results returned from the stored proc in succession. Running this class shows that any resultsets are returned first and then update counts last regardless of the order in which they appear in the stored proc. Maybe there is nothing unusual here, it may be that Java is designed to return any Resultsets first by default even if they didn't happen first in the stored procedure?
    3. In my stored procedure, if the UPDATE happens last then callablestatement.getUpdateCount() will return the correct number of updated rows.
    4. If the UPDATE is followed by a SELECT (see above) then callablestatement.getUpdateCount() will return ZERO even though rows were updated.
    5. I tested it with the stored proc doing SELECT - UPDATE - SELECT and again getUpdateCount() returns ZERO.
    6. I tested it with the stored proc doing SELECT - UPDATE - SELECT - UPDATE and this time getUpdateCount() returns the number rows updated by the last UPDATE and not the first.
    My Setup:
    Mac OS X 10.3.9
    Java 1.4.2
    mysql database 5.0.19
    mysql-connector 5.1.10 (connector/J)
    Maybe I have exposed a bug in JDBC?
    Thanks for your help.

    plica10 wrote:
    Jschell thank you for your response.
    I certainly don't mean to be rude but I often get taken that way. I like to state facts as I see them. I'd love to be proved wrong because then I would understand why my code doesn't work!
    Doesn't matter to me if you are rude or not. Rudeness actually makes it more entertaining for me so that is a plus. Nothing I have seen suggests rudeness.
    In response to your post:
    When a MySql stored procedure has multiple sql statements such as SELECT and UPDATE these statements each produce what the Java API documentation refers to as 'results'. A Java class can cycle through these 'results' using callableStatement dot getMoreResults(), getResultSet() and getUpdateCount() to retrieve the resultset object produced by Select queries and updateCount produced by Inserts, Deletes and Updates.
    As I read your question it seems to me that you have already proven that it does not in fact do that?
    You don't have to read this but in case you think I'm mistaken, there is more detail in the following website under the heading 'Using the Method execute':
    http://docsrv.sco.com/JDK_guide/jdbc/getstart/statement.doc.html#1000107
    Sounds reasonable. But does not your example code prove that this is not what happens for the database and driver that you are using?
    Myself I dont trust update counts at all since, in my experience some databases do not return them. And per other reports sometimes they don't return the correct value either.
    So there are two possibilities - your code is wrong or the driver/database does not do it. For me I would also question whether in the future the driver/database would continue to behave the same if you did find some special way to write your SQL so it does do it. And of course you would also need to insure that every proc that needed this would be written in this special way. Hopefully not too many of those.
    So this functionality is built into java but is not in common use amongst programmers. My java class did successfully execute a stored proc which Selected from and then finally Updated a table. My code displayed the contents of the Select query and told me how many rows were affected by the update.
    It isn't "built into java". It isn't built into jdbc either. If it works at all then the driver and by proxy the database are responsible for it. I suspect that you would be hard pressed to find anything in the JDBC spec that requires what that particular link claims. I believe it is difficult to find anything that suggests that update counts in any form are required.
    So you are left with hoping that a particular driver does do it.
    I suppose it is rare that you would want to do things this way. Returning rowcounts in OUT parameters would be easier but I want my code to be modular enough to cover the situation where a statement may return more than one ResultSet object, more than one update count, or a combination of ResultSet objects and update counts. The sql may need to be generated dynamically, its statements may be unknown at compile time. For instance a user might have a form that allows them to build their own queries...
    Any time I see statements like that it usually makes me a bit uncomfortable. If I am creating data layers I either use an existing framework or I generate the code. For the latter there is no generalization of the usage. Every single operation is laid out in its own code.
    And I have in fact created generalized frameworks in the past before. I won't do it again. Benefits of the other idioms during maintenance are too obvious.

  • Calling Report From Oracle Forms

    Hi
    I am calling this one report from oracle forms, I am using global temporary table to run that report. I am first inserting data into the temporary table through oracle form and then i am calling report in that form to view the data in that temporary table. The problem is, we can not view the data of an other session if we are using temporary table. When i call report from that form a new session get created due to which i can not see the data. Is there any method of calling report from oracle form that a same session is used to run the report?
    Thanks.

    As you mention Forms and Reports do not share the database session. I had the same problem and resolved it using record groups and DATA_PARAMETER to transfer data from Forms to Reports. You could also read the Note 110495.1 on Metalink to find useful information regarding this issue.
    Adi

  • Call ejb from browsers

    Hello Developers!
    I deployed my ejb to OAS4081. I call that
    from JDeveloper so it good. But when I try
    to call from applet in IExpl5 I can't
    instantiate the ORB. I've got a com.ms.security.SecurityException : oracle.oas.orb.CORBA.ORB.init
    I coded the CLASSPATH(oasoorb(yoj),client,
    ejbapi...) perfectly, I think.
    If anybody could help, please...
    Thanx!

    Hi there,
              I saw someone on this group had a problem to locate proper classpath
              to call EJB from JSP. I thought if you call EJB from classpath, you are
              calling the bean. But you loss all the EJB functions. To be able to utilize
              EJB features like object pooling. You need to call it from Weblogic server
              using url/jndi, not from the jar directly.
              Any comment? Am I right?
              BTW, my question about calling EJB from JSP means calling through URL,
              not a local path.
              Thank you
              >-------------------------------------------------------------------->
              Jim wrote in message <[email protected]>...
              >Hi there,
              > Can I call EJB from JSP? Is there a particular security setting or
              >concern for Weblogic? Is there an coding example?
              >
              >Thank you
              >
              >
              

  • Passing data from Oracle stored procedures to Java

    We're going to write a new web interface for a big system based on Oracle database. All business rules are already coded in PL/SQL stored procedures and we'd like to reuse as much code as possible. We'll write some new stored procedures that will combine the existing business rules and return the final result dataset.
    We want to do this on the database level to avoid java-db round trips. The interface layer will be written in Java (we'd like to use GWT), so we need a way of passing data from Oracle stored procedures to Java service side. The data can be e.g. a set of properties of a specific item or a list of items fulfilling certain criteria. Would anyone recommend a preferable way of doing this?
    We're considering one of the 2 following scenarios:
    passing objects and lists of objects (DB object types defined on the schema level)
    passing a sys_refcursor
    We verified that both approaches are "doable", the question is more about design decision, best practice, possible maintenance problems, flexibility, etc.
    I'd appreciate any hints.

    user1754151 wrote:
    We're going to write a new web interface for a big system based on Oracle database. All business rules are already coded in PL/SQL stored procedures and we'd like to reuse as much code as possible. We'll write some new stored procedures that will combine the existing business rules and return the final result dataset.
    We want to do this on the database level to avoid java-db round trips. The interface layer will be written in Java (we'd like to use GWT), so we need a way of passing data from Oracle stored procedures to Java service side. The data can be e.g. a set of properties of a specific item or a list of items fulfilling certain criteria. Would anyone recommend a preferable way of doing this?
    We're considering one of the 2 following scenarios:
    passing objects and lists of objects (DB object types defined on the schema level)
    passing a sys_refcursor
    We verified that both approaches are "doable", the question is more about design decision, best practice, possible maintenance problems, flexibility, etc.
    I'd appreciate any hints.If logic is already written in DB, and the only concern is of passing the result to java service side, and also from point of maintenance problem and flexibility i would suggest to use the sys_refcursor.
    The reason if Down the line any thing changes then you only need to change the arguments of sys_refcursor in DB and as well as java side, and it is much easier and less efforts compare to using and changes required for Types and Objects on DB and java side.
    The design and best practise keeps changing based on our requirement and exisiting design. But by looking at your current senario and design, i personally suggest to go with sys_refcursor.

  • How to connect to UNIX OS from oracle stored procedure

    Hi,
    I need to connect to UNIX OS from oracle stored procedure.
    Curently working in Oracle9i.
    I tried in google but I could'nt get any.
    Can you send me pointers on how to do this.
    Thanks,
    Kavitha.

    Can use Java Stored Proc, or an External Proc.
    Java method:
    create or replace and compile Java Source named "OSCommand" as
    -- java:        OS COMMAND
    -- descr:       Executes an Operating System Command using the JAVA RTS
    -- IN parameter:        os command to execute (including fully qualified path names)
    -- OUT parameter:       returncode [\nstring]
    --                      where string a max of 32000 chars of the output of the command
    --                      (note that \n is used as separators in the string)
    --                      returncode=-1   Java RTS error occurred (e.g. command does not exist)
    --                      returncode=255  o/s command failed (e.g. invalid command params)
    import java.io.*;
    import java.lang.*;
    public class OSCommand{
            public static String Run(String Command){
                    Runtime rt = Runtime.getRuntime();
                    int     rc = -1;
                    try{
                            Process p = rt.exec( Command );
                            int bufSize = 32000;
                            int len = 0;
                            byte buffer[] = new byte[bufSize];
                            String s = null;
                            BufferedInputStream bis = new BufferedInputStream( p.getInputStream(), bufSize );
                            len = bis.read( buffer, 0, bufSize );
                            rc = p.waitFor();
                            if ( len != -1 ){
                                    s = new String( buffer, 0, len );
                                    return( s );
                            return( rc+"" );
                    catch (Exception e){
                            e.printStackTrace();
                            return(  "-1\ncommand[" + Command + "]\n" + e.getMessage() );
    show errors
    create or replace function osexec( cCommand IN string ) return varchar2 is
    -- function:    OS EXEC
    -- descr:       Executes an Operating System Command
    language        JAVA
    name            'OSCommand.Run(java.lang.String) return java.lang.String';
    show errors===
    This can then be used from PL/SQL and even SQL. e.g.
    SQL> select osexec( '/bin/date' ) from dual;
    OSEXEC('/BIN/DATE')
    Wed Nov  9 13:30:13 SAST 2005
    SQL>Note the Java permissions required - replace FOO with the name of applicable Oracle schema
    ==begin
            dbms_java.grant_permission(
                    'FOO',
                    'SYS:java.io.FilePermission',
                    '<<ALL FILES>>',
                    'execute'
            dbms_java.grant_permission(
                    'FOO',
                    'SYS:java.lang.RuntimePermission',
                    'writeFileDescriptor',
            dbms_java.grant_permission(
                    'FOO',
                    'SYS:java.lang.RuntimePermission',
                    'readFileDescriptor',
            commit;
    end;
    /==
    Last thing... note that opens a potential giant size security hole into the Oracle Server Platform. So implement it properly using a proper Oracle security model.

  • Calling EJB from app client

    Hello, everybody,
    I'm very new at EJB and I'm trying to learn it.
    I have created Enterprise Application using Netbeans IDE, I have EJB and APP client. What I want is to connect to my MySql database and get some info from table.
    For e.g. Login and Password.
    How can I call EJB from my client app which connects to my database and gets information I need?

    What server you are using?
    if you use jboss AS ,here is a simple Main class how to connect EJB and access ejb methods:
    package com.david.ejb.client;
    import java.util.Properties;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.rmi.PortableRemoteObject;
    import com.david.ejb.domain.Person;
    import com.david.ejb.domain.PersonRemote;
    public class Main {
         public static void main(String[] args) {
              try {
                   Context ctx = getInitialContext();
                   Object obj = ctx.lookup("PersonSessionRemote/remote");
                PersonRemote pr=(PersonRemote)PortableRemoteObject.narrow(obj, PersonRemote.class);
                Person p=new Person();
                p.setName("david");
                pr.addPerson(p);
                pr.findPerson(1);
                   // System.out.print(br.find(pk).getAuthor_name());
              } catch (Exception ex) {
                   ex.printStackTrace();
         private static Context getInitialContext() throws NamingException {
              Properties p = new Properties();
              p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory");
              p.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
              p.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
              return new InitialContext(p);
    }Person is ant @Entity and PersonRemote is remote interfaces, to connect database you have to make datasource file at jboss-4.2.3.GA\server\default\deploy
    simle mysql-ds.xml looks like this:
    datasources>
       <local-tx-datasource>
          <jndi-name>some name</jndi-name>
          <connection-url>jdbc:mysql://localhost:3306/dbname</connection-url>
          <driver-class>com.mysql.jdbc.Driver</driver-class>
          <user-name>root</user-name>
          <password>root password</password>
          <min-pool-size>5</min-pool-size>
          <max-pool-size>100</max-pool-size>
          <idle-timeout-minutes>15</idle-timeout-minutes>
          <exception-sorter-class-name>com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter</exception-sorter-class-name>
          <valid-connection-checker-class-name>com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker</valid-connection-checker-class-name>
       </local-tx-datasource>
    </datasources>also at resources/META-INF directory you must have persistence.xml like this
    <persistence>
         <persistence-unit name="SimpleEjb">
              <jta-data-source>java:/some name</jta-data-source>
              <properties>
                   <property name="hibernate.hbm2ddl.auto" value="update" />
                   <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
                   <property name="hibernate.show_sql" value="true"/>
                   <property name="hibernate.format_sql" value="true"/>
              </properties>
         </persistence-unit>
    </persistence>

Maybe you are looking for