Calling plsql block in java

Hi
Needs some help, urgently.
i have to call/execute a plsql block in java program.
block is similar to this
declare
CURSOR l_csr IS
select empname, empid, empdate from emp
order by empid;
l_empid NUMBER;
l_empdate DATE;
l_empname varchar2(30);
o_dateProfileId NUMBER;
o_dayofweekprofileid NUMBER;
begin
open l_csr;
loop
FETCH l_csr INTO l_empid , l_empname , l_empdate;
EXIT WHEN l_csr%NOTFOUND;
DETERMINEEMPPROFILE(l_empdate,o_dateProfileId,o_dayofweekprofileid,l_empid ,FALSE);
IF(o_dateProfileId IS NOT NULL) THEN
SELECT totaljobs INTO l_max1 FROM dateprofile WHERE dateprofileid = o_dateprofileid;               
ELSE
SELECT totaljobs INTO l_max1 FROM dayofweekprofile WHERE dayofweekprofileid = o_dayofweekprofileid;
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('SQLCODE = ' || SQLCODE);
END;
i need to call this in java program and take the results of l_max1.
can someone provide an example of hot to do this or sample code
appreciate any help

I'm assuming this is for Oracle. Take a look at this article [url=http://www.enterprisedt.com/publications/oracle/result_set.html
]here for an example of how to use java to parse a result set from an Oracle procedure.

Similar Messages

  • Oracle BI 11.1.1.7.1: Calling BI webservices from Plsql Procedure: ORA-29532: Java call terminated by uncaught Java exception: java.lang.NoClassDefFoundError

    Hi,
         I have a requirement of calling BI webservices from Plsql stored procedure. I generated all my wsdl java classes and loaded them into the database. However, when I tried to call one of my java class using stored procedure, it is giving me"ORA-29532: Java call terminated by uncaught Java exception: java.lang.NoClassDefFoundError".
    *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.
    But all my dependency classes are present in database as java class objects and are valid. Can some one help me out of this?

    Stiphane,
    You can look in USER_ERRORS to see if there's anything more specific reported by the compiler. But, it could also be the case that everything's OK (oddly enough). I loaded the JavaMail API in an 8.1.6 database and also got bytecode verifier errors, but it ran fine. Here are the errors I got when loading Sun's activation.jar, which ended up not being a problem:
    ORA-29552: verification warning: at offset 12 of <init> void (java.lang.String, java.lang.String) cannot access class$java$io$InputStream
    verifier is replacing bytecode at <init> void (java.lang.String, java.lang.String):12 by a throw at offset 18 of <init> void (java.lang.String, java.lang.String) cannot access class$java$io$InputStream
    verifier is replacing bytecode at <init> void (java.lang.String, java.lang.String):18 by a throw at offset 30 of <init> void (java.lang.String, java.lang.String) cannot access class$java$io$InputStream
    verifier is replacing bytecode at <init> void (java.lang.String, java.lang.String):30 by a throw
    Hope this helps,
    -Dan
    http://www.compuware.com/products/devpartner/db/oracle_debug.htm
    Debug PL/SQL and Java in the Oracle Database

  • Call unix script within plsql block

    Hi all,
    can i call a unix script within a plsql block for example
    my unix script name is - Diff_dataload_process.sh
    declare
    begin
    select * from ......;
    Diff_dataload_process.sh
    exception
    end;
    please help me.
    Thanks,
    Krupa

    Hi, I think you need something like this:
         DBMS_SCHEDULER.create_program
         (program_name => 'sch_program',
    program_type => 'EXECUTABLE',
    program_action => '/home/nobody/input/test_job.sh',
    number_of_arguments => 0,
    enabled => TRUE,
    comments => 'Test Program'
    end;
    and there's another ways to do it:
    [calling shell|http://www.dba-oracle.com/t_execute_shell_script_plsql_procedure.htm]

  • Need to write a plsql block for calling another procedure.

    Hi Guys,
    I have a requirement to write a plsql block and to call another procedure which is having 5 parameters (each parameter having multiple values). Calling procedure generates one SQL query and it needs to be generated all combinations and print in another table.
    I need to pass multiple values for first three parameters from my PLSQL block and run.
    call sample proc:
    procedure(
    param1 varchar2,
    param2 p_varchar2,
    param3 p_varchar2,
    param4 in varchar2,
    param5 in number
    is
    begin
    ls_sql_query := 'with client_query as (select * from table)';
    end;
    Thanks in advance!
    Rgds,
    LRK

    This article is on exactly your subject. It is worth a careful read.
    Ask Tom: On Popularity and Natural Selection
    I paraphrase: "Always code a reference to every possible bind variable but do so in such a way that the optimizer removes the bind variable for us if we aren't going to actually use it in that particular execution of the SQL statement."
    P.S. This is the same answer I gave when you asked the same question earlier.

  • Calling a PLSQL package from java

    Hi All
    I have a problem calling a package from java. I have to pass a Date to the package which is a String in java.
    How can I typecast it to the PLSQL Date from a java String.
    Here is my below code for reference. The below code does not works because of typecasting problem.I tried to_date() also in java, but it is not working.
    cstmt=connDbConn.prepareCall("{call pkage.PACK1(?)}"); cstmt.setString(1,"01-JAN-2009");

    keyanwb wrote:
    How can I typecast it to the PLSQL Date from a java String.That datatype in Oracle contains a date and time component.
    Thus you should consider exactly what storing the date only component means in terms of the timezone that the Oracle server is using.

  • Curious thing while calling a procedure from Java !...

    Hi !. My name is Agustin and my doubt would be the following one... I am working for a e-business comp and they asked me to call a procedure from java... The code is the following one:
    CallableStatement cs = null;
    System.out.println("Fecha Nro. 1: " + paramFechaDesde);
    System.out.println("Fecha Nro. 2: " + paramFechaHasta);
    try
    cs = getDBTransaction().createCallableStatement("{call paq_w_ListadoSiniestralidadART. p_sinsiniest(?,?,?,?) }",0);
    cs.registerOutParameter(4,OracleTypes.VARCHAR);
    cs.setInt(1,paramContrato.intValue());
    cs.setString(2,paramFechaDesde);
    cs.setString(3,paramFechaHasta);
    cs.setString(4,paramNombreArchivo);
    cs.executeQuery();
    String nomArchivo = cs.getString(4);
    System.out.println("### " + nomArchivo +" ###");
    catch(SQLException e)
    The weird thing is that, I was expecting a big big exception but the only thing I got is
    ### Error ###
    The String I am expecting is a file's name !; so I am a little bit confused...
    Also I didn't know where to post so If it's in the wrong category... I apologize !... If anyone need more details, I'll be checking out... The account I am working on is an Insurance company, who is the one who provide access to the DB and the procedures... So I can't check what's inside...

    Please provide your Java and OS versions, the JDBC jar file and the Oracle DB version being used when you post.
    >
    I was expecting a big big exception
    >
    Then why do you have an empty exception block? That just makes it disappear so you won't see one if it happens.
    And your code has
    cs.registerOutParameter(4,OracleTypes.VARCHAR);
    cs.setString(4,paramNombreArchivo);You use 'registerOutParameter' for an OUT parameter and the 'setXXX' methods for other parameters.
    Remove the 'setSTring' for the OUT parameter.
    Then as malcollmmc already said
    >
    Sounds like the PL/SQL is returning "Error" as the 4th parameter of the call
    >
    The actual value returned by PL/SQL is strictly determined by the PL/SQL code and Java and JDBC are not involved.
    Fix the code problems, retest, and folllowup with whoever wrote the code if it still returns ERROR.

  • Help required in understanding of static blocks in java

    Hi ,
    Can some one help me in understanding the difference between static blocks in java....also what is the difference in declaring some static variables in a class and and declaring some variables in a static block? From an architecture viewpoint when should one use static blocks in Java?

    Static blocks are piece of code that can beexecuted
    before creating an instance of a class.static blocks are executed once, when the class
    itself is loaded by the JVM. They are not executed
    before creating each instance of a class.
    For example whatever you include in the mainn method will be
    executed without you having to create the instanceof
    the class using the new operator. So you can saythe
    main method is a static block.main is not a static initialisation block but a
    static method. a special case static method at that -
    it is only executed when the containing class is
    specified as a parameter to the JVM. (unless you
    specifcally call it elsewhere in code - but that
    would be bad form).
    in answer to the original post, static variables
    belong to the class. each instance of the class share
    the same static variables. Public static vars can be
    accessed by prefixing them with the class name. A
    static initialisation block can be used to
    initialise static variables. Variables declared
    within the static initialisation block exist only
    within the scope of the block.
    e.g.
    public class Foo {
    static Bar bar;        // static member variable
    // static initialisation block
    static {
    // variable declared in static block...
    String barInfo =
    arInfo = System.getParameter("barInfo");
    // ... used to initialise the static var
    bar = new Bar(barInfo);
    So is the only purpose of static initialization blocks is to initialize static variables? Does the initialization of static variables inside a static block make any difference in performance? If yes , then how ?

  • How to call plsql procedure or function and getting back the string?

    Hi Everyone,
    i am using Jdev 11.1.1.5.0.
    i have a requirement to call plsql procedure or function from my backing bean java file and get back the returned value from the procedure or function.
    what piece of simple code i need to write in my backing bean?
    please suggest.
    Thanks.

    As always you write the method to call he pl/sql in the application module, expose this method to the client (so you see it in the datacontroll) then create a operation binding to the method and call this operation from the bean. The result you get by operation.getResult();
    You should never call pl/sql from the bean directly!
    The doc shows how to call the procedure from an application module: http://docs.oracle.com/cd/E21764_01/web.1111/b31974/bcadvgen.htm#sm0297
    Timo

  • PLSQL BLOCK TO RUN A TYPE PROCEDURE

    I have created a type called bank_account which has many member functions and procedures to open ,close,deposit and withdraw.I have created a type body where these member functions are defined.i have created a table based on this type.
    Now my problem is that the plsql block that i have written to call the member function open gives the following error:
    method dispatch on NULL SELF argument is disallowed
    the plsql block is as given below:
    SQL> run
    1 declare
    2 amount real;
    3 a bank_account(this is the type);
    4 begin
    5 amount:=&amount;
    6 a.open(amount);
    7 dbms_output.put_line('account opened');
    8* end;
    Enter value for amount: 5
    old 5: amount:=&amount;
    new 5: amount:=5;
    declare
    ERROR at line 1:
    ORA-30625: method dispatch on NULL SELF argument is disallowed
    ORA-06512: at line 6
    please help me to solve my problem
    null

    I have created a type called bank_account which has many member functions and procedures to open ,close,deposit and withdraw.I have created a type body where these member functions are defined.i have created a table based on this type.
    Now my problem is that the plsql block that i have written to call the member function open gives the following error:
    method dispatch on NULL SELF argument is disallowed
    the plsql block is as given below:
    SQL> run
    1 declare
    2 amount real;
    3 a bank_account(this is the type);
    4 begin
    5 amount:=&amount;
    6 a.open(amount);
    7 dbms_output.put_line('account opened');
    8* end;
    Enter value for amount: 5
    old 5: amount:=&amount;
    new 5: amount:=5;
    declare
    ERROR at line 1:
    ORA-30625: method dispatch on NULL SELF argument is disallowed
    ORA-06512: at line 6
    please help me to solve my problem
    null

  • Unable to insert row in object table from plsql block

    I have table called test based on an object type. When I issue an insert statement from sqlplus, the row is inserted. The exact same sql statement in a plsql block gives the error below. Any ideas? (it is not a constraint problem).
    SQL> insert into test values( 3,2,1,1,'asp',1,'mach' );
    1 row created.
    SQL> begin
    2 insert into test values( 3,2,1,1,'asp',1,'mach' );
    3 end;
    4 /
    insert into test values( 3,2,1,1,'asp',1,'mach' );
    ERROR at line 2:
    ORA-06550: line 2, column 16:
    PL/SQL: ORA-06552: PL/SQL: Compilation unit analysis terminated
    ORA-06553: PLS-302: component 'DOCUMENT' must be declared
    ORA-06550: line 2, column 4:
    PL/SQL: SQL Statement ignored
    (ddl)
    CREATE OR REPLACE type document as object
    DOC_ID NUMBER (38),
    BATCH_ID NUMBER (38),
    STATE NUMBER (2),
    TRANSIENT NUMBER (2),
    ASP VARCHAR2 (20),
    USER_ID NUMBER (6),
    MACHINE VARCHAR2 (30),
    MEMBER PROCEDURE setState,
    MEMBER function getState RETURN NUMBER
    ) not final;
    create table test of document;

    Hi Adam
    You need to instantiate your object type in your insert statement(while doing through PL/SQL block), so try like this
    Insert into test values(document(1,2,'CO',55,'xyz','kkk','PENTIUM'));
    The reason you were successful through SQLPLUS was that, SQLPLUS automatically instantiate the values into object type.
    Qurashi

  • PLSQL Entity or Java Entity

    I have requirement like this.
    I have to update the table underlying my page and also should insert in Interface table.
    Which will be best.PLSQL Entity or Java EO.

    Have a Java EO to insert data into your table..
    Before commit insert data into the intereface table by calling a pl/sql procedure..
    refer http://prasanna-adf.blogspot.com/2008/11/callable-statement.html to invoke callable statement from OAF.
    --Prasanna                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Using Execute Immediate in PLSQL block Vs Stand alone procedure

    I am facing very unusual ( atleast unusual to me ) with usage of "Execute Immediate" statement.
    I have a table dynamic_sql with one column plsql_block as VARCHAR2(4000);
    I have stored some PLSQL blocks ('DECLARE ..... BEGIN.... END.... ) in this column .
    Now I want to execute these PLSQL blocks one after other depending on certain conditions .
    In order to archive this I wrote a PLSQL block as below
    DECLARE
    Cursor c1 is
    select plsql_block from dynamic_sql
    begin
    for irec in c1
    loop
    <<< Condition >>>
    begin
    execute_immediate(irec.plsql_block);
    exception
    when others then
    raise_application_error(-20001,'error ' ||irec.plsql_block||' '||sqlerrm);
    end loop ;
    end ;
    With above PLSQL block , "execute immediate" is executing PLSQL block successfully without any error
    But When I converted above PLSQL block into standalone procedure as shown below , I am getting error .
    CREATE OR REPLACE procedure test AS
    Cursor c1 is
    select plsql_block from dynamic_sql
    begin
    for irec in c1
    loop
    <<< Condition >>>
    begin
    execute_immediate(irec.plsql_block);
    exception
    when others then
    raise_application_error(-20001,'error ' ||irec.plsql_block||' '||sqlerrm);
    end loop ;
    end ;
    BEGIN
    test;
    end ;
    It is showing the value of irec.plsql_block but not showing sqlerrm...
    I found this is very unusual as I am able to execute "execute immediate" statement with PLSQL block but not with similar procedure .
    can anybody explain me why this is happening?
    Thanks in Advance
    Amit

    Hello,
    It doesn't make any sense to add SQLERRM for user defined exception, unless you want to raise application error for already defined error (e.g NOT_DATA_FOUND, ..)
    Check following piece of code and its output,
    CREATE OR REPLACE PROCEDURE myinsert1
    AS
       v_count   NUMBER;
       v_sql     VARCHAR2 (300);
    BEGIN
       v_sql :=
          'INSERT INTO ENTITY_EMPLOYEE VALUES(0,''TIM'',''LASTNAME'',10000)';
       BEGIN
          EXECUTE IMMEDIATE v_sql;
          COMMIT;
       EXCEPTION
          WHEN OTHERS
          THEN
             DBMS_OUTPUT.PUT_LINE (SUBSTR (SQLERRM, 1, 300));
             RAISE_APPLICATION_ERROR (-20002, 'My Error ' || SQLERRM, TRUE);
             RAISE;
       END;
    END;
    Output._
    ORA-20002: My Error ORA-00001: unique constraint (ENTITY_EMPLOYEE_PK) violated
    ORA-06512: at "MYINSERT1", line 21
    ORA-00001: unique constraint (ENTITY_EMPLOYEE_PK) violated
    ORA-06512: at line 2
    Regrds

  • Calling a WebServices From Java Stored Proc fails with Connection refused

    I have followed the example in Note:220662.1 on Metalink step by step.
    I am using two windows machines (2000 SP4). I have Oracle 9.2.0.5 EE on one of them and OC4J 9.0.4 standalone on the other(running on JVM 1.4.2_05-b04). The 2 servers "see" each other over the network.
    I can execute the stub from the database machine:
    C:\WebServices\HelloWorld>java HelloWorldImplWSStub
    Hello World - The current time is Sat Aug 21 11:56:20 EDT 2004When running it from the database, I get:
    SQL> select ws_hello_world from dual;
    select ws_hello_world from dual
    ERROR at line 1:
    ORA-29532: Java call terminated by uncaught Java exception: [SOAPException:
    faultCode=SOAP-ENV:IOException; msg=Connection refused;
    targetException=java.net.ConnectException: Connection refused]
    Elapsed: 00:00:21.02The trace file generated on the database server machine looks like:
    [SOAPException: faultCode=SOAP-ENV:IOException; msg=Connection refused; targetException=java.net.ConnectException: Connection refused]
      at oracle.soap.transport.http.OracleSOAPHTTPConnection.send(OracleSOAPHTTPConnection.java:765)
      at org.apache.soap.rpc.Call.invoke(Call.java:261)
      at HelloWorldImplWSStub.sayHelloWorld(HelloWorldImplWSStub.java:52)Here is the stub code generated using JDeveloper 9.0.5.1:
    import oracle.soap.transport.http.OracleSOAPHTTPConnection;
    import org.apache.soap.encoding.SOAPMappingRegistry;
    import java.net.URL;
    import org.apache.soap.rpc.Call;
    import org.apache.soap.Constants;
    import java.util.Vector;
    import org.apache.soap.rpc.Response;
    import org.apache.soap.rpc.Parameter;
    import org.apache.soap.Fault;
    import org.apache.soap.SOAPException;
    import java.util.Properties;
    public class HelloWorldImplWSStub  {
      public HelloWorldImplWSStub() {
        m_httpConnection = new OracleSOAPHTTPConnection();
        m_smr = new SOAPMappingRegistry();
      public static String endpoint = "http://oc4jsrv:8888/MyWorkarea-OC4J-context-root/HelloWorldImplWS";
      public String getEndpoint() {
        return _endpoint;
      public void setEndpoint(String endpoint) {
        _endpoint = endpoint;
      private static OracleSOAPHTTPConnection m_httpConnection = null;
      private static SOAPMappingRegistry m_smr = null;
      public static String sayHelloWorld() throws Exception {
        String returnVal = null;
        URL endpointURL = new URL(_endpoint);
        Call call = new Call();
        call.setSOAPTransport(m_httpConnection);
        call.setTargetObjectURI("HelloWorldImplWS");
        call.setMethodName("sayHelloWorld");
        call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
        Vector params = new Vector();
        call.setParams(params);
        call.setSOAPMappingRegistry(m_smr);
        Response response = call.invoke(endpointURL, "");
        if (!response.generatedFault()) {
          Parameter result = response.getReturnValue();
          returnVal = (String)result.getValue();
        else {
          Fault fault = response.getFault();
          throw new SOAPException(fault.getFaultCode(), fault.getFaultString());
        return returnVal;
      public void setMaintainSession(boolean maintainSession) {
        m_httpConnection.setMaintainSession(maintainSession);
      public boolean getMaintainSession() {
        return m_httpConnection.getMaintainSession();
      public void setTransportProperties(Properties props) {
        m_httpConnection.setProperties(props);
      public Properties getTransportProperties() {
        return m_httpConnection.getProperties();
       public static void main(String[] argv) throws Exception   {    
        HelloWorldImplWSStub hstub = new HelloWorldImplWSStub();    
        System.out.println(hstub.sayHelloWorld());  
    }The PL/SQL function code:
    CREATE OR REPLACE FUNCTION ws_hello_world RETURN VARCHAR2
    AS LANGUAGE JAVA
    NAME 'HelloWorldImplWSStub.sayHelloWorld() return java.lang.String';Any help would be greatly appreciated.

    Hello,I have the same problem. Did you find any solution to it?
    Thanks. Diego (Argentina)

  • Call .bat file from java code

    I need to call an application that uses a .bat file to execute from a java program. Is that possible?
    This is the .bat file:
    importcli.exe ciaf2735 C:\Importcli\files\SAI2735*.txt  
    importcli.exe ciaf2735 C:\Importcli\files\CI2735*.txt  
    importcli.exe ciaf2735 C:\Importcli\files\SC2735*.txt  
    importcli.exe db1800 C:\Importcli\files\*.mdb

    magaupe wrote:
    I need to call an application that uses a .bat file to execute from a java program. Is that possible?
    This is the .bat file:
    importcli.exe ciaf2735 C:\Importcli\files\SAI2735*.txt  
    importcli.exe ciaf2735 C:\Importcli\files\CI2735*.txt  
    importcli.exe ciaf2735 C:\Importcli\files\SC2735*.txt  
    importcli.exe db1800 C:\Importcli\files\*.mdb
    Hmmm, I wonder what would happen if there were a web search engine and you could research like this:
    [http://www.google.com/search?hl=en&q=call+.bat+file+from+java]

  • "ORA-29532: Java call terminated by uncaught Java exception

    Dear Oracle:
    I am trying to establish an HTTPS connection from a Java stored
    procedure that is wrapped in a PL/SQL procedure and loaded into a
    Package. We are running on Oracle 8.1.7.
    My Java code compiles and runs fine when run stand-alone outside
    Oracle; I can establish the connection to a secure server and talk to
    the server. However when I load this Java class (using the loadjava
    utility) this class can no longer run and I get a the following
    exception:
    "ORA-29532: Java call terminated by uncaught Java exception:
    javax.net.ssl.SSLException: SSL handshake failed:
    X509CertChainIncompleteErr"
    I have tried loading the JSSE from Sun and I still get the same error.
    Searching in the Discussing Forums I found the following link (which
    describes a procedure that logs into the UPS secure server site and
    grabs some XML) http://osi.oracle.com/~mbpierma/SSL_Java_DB.html .
    This code works ok if we try to connect to UPS server. However this
    code doesn't work if we try to log in to a different server (such as
    ???). If I modify this code slightly and try to log to any other
    sever server I get the same error as the one above. Investigation
    lead us to understand that the certificate at the UPS web site is a
    self-signed certificate -- not one generated by a major 'recognized'
    authority such as Verisign or Thawte.
    Further research pointed me to the following URL
    http://www.znow.com/sales/oracle/network.816/a76932/appf_ora.htm#619367
    This URL has the documentation for JAVA SSL for 8.1.6 which I figure
    I could read and try to make it work in 8.1.7.
    I looked at your Secure Hello World example, however the code is
    missing the most critical parts of the whole example, it does not
    specify where the certificate or any of the security settings come
    from (see the attached JavaCertExample.txt file).
    So, my questions are the following:
    1) What should I do to avoid the error mentioned above?
    2) Do you have a sample piece of code that describes how to make a
    HTTPS connection using a Java stored procedure?
    3) Can I make the HTTPS connection using a URL class and not using
    sockets directly?
    4) Do I need to load the JSEE provided by Sun?
    5) Will the solution be different for Oracle 9i?
    // SecureHelloClient.java
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import javax.net.ssl.*;
    import javax.security.cert.X509Certificate;
    import oracle.security.ssl.OracleSSLCredential;
    import oracle.security.ssl.OracleSSLSocketFactory;
    import oracle.security.ssl.OracleSSLProtocolVersion;
    import oracle.security.ssl.OracleSSLSession;
    public class SecureHelloClient
    public static void main(String argv[])
    String hostName = "localhost";
    if(argv.length != 0)
    String hostName = argv[0];
    // Set the SSLSocketFactoryImpl class as follows:
    java.util.Properties prop = System.getProperties();
    prop.put("SSLSocketFactoryImplClass",
    "oracle.security.ssl.OracleSSLSocketFactoryImpl");
    try
    // Get the default socket factory
    OracleSSLSocketFactory sSocFactory
    = (OracleSSLSocketFactory)SSLSocketFactory.getDefault();
    sSocFactory.setSSLProtocolVersion(OracleSSLProtocolVersion.SSL_Version_3_0);
    OracleSSLCredential sslCredObj = new OracleSSLCredential();
    // Where did these values come from? caCert, userCert, trustedCert,
    // Set the certificate chain and private key if the
    // server requires client authentication
    sslCredObj.addCertChain(caCert)
    sslCredObj.addCertchain(userCert)
    sslCredObj.setPrivateKey(userPvtKey, userPassword)
    // Populate credential object
    sslCredObj.addTrustedCert(trustedCert);
    sSocFactory.setSSLCredentials(sslCredObj);
    // Create the socket using factory
    SSLSocket jsslSoc =
    (SSLSocket)sSocFactory.createSocket(hostName, 8443);
    String [] ciphers = jsslSoc.getSupportedCipherSuites() ;
    // Select the ciphers you want and put them.
    // Here we will put all availabel ciphers
    jsslSoc.setEnabledCipherSuites(ciphers);
    // We are creating socket in client mode
    jsslSoc.setUseClientMode(true);
    // Do SSL handshake
    jsslSoc.startHandshake();
    // Print negotiated cipher
    System.out.println("Negotiated Cipher Suite: "
    +jsslSoc.getSession().getCipherSuite());
    System.out.println("");
    X509Certificate[] peerCerts
    = ((javax.net.ssl.SSLSocket)jsslSoc).getSession().getPeerCertificateChain();
    if (peerCerts != null)
    System.out.println("Printing server information:");
    for(int i =0; i ? peerCerts.length; i++)
    System.out.println("Peer Certificate ["+i+"] Information:");
    System.out.println("- Subject: " + peerCerts.getSubjectDN().getName());
    System.out.println("- Issuer: " + peerCerts[i].getIssuerDN().getName());
    System.out.println("- Version: " + peerCerts[i].getVersion());
    System.out.println("- Start Time: " + peerCerts[i].getNotBefore().toString());
    System.out.println("- End Time: " + peerCerts[i].getNotAfter().toString());
    System.out.println("- Signature Algorithm: " + peerCerts[i].getSigAlgName());
    System.out.println("- Serial Number: " + peerCerts[i].getSerialNumber());
    else
    System.out.println("Failed to get peer certificates");
    // Now do data exchange with client
    OutputStream out = jsslSoc.getOutputStream();
    InputStream in = jsslSoc.getInputStream();
    String inputLine, outputLine;
    byte [] msg = new byte[1024];
    outputLine = "HELLO";
    out.write(outputLine.getBytes());
    int readLen = in.read(msg, 0, msg.length);
    if(readLen > 0)
    inputLine = new String(msg, 0, readLen);
    System.out.println("");
    System.out.println("Server Message:");
    System.out.println(inputLine );
    else
    System.out.println("Can't read data from client");
    // Close all sockets and streams
    out.close();
    in.close();
    jsslSoc.close();
    catch(SSLException e)
    System.out.println("SSL exception caught:");
    e.printStackTrace();
    catch(IOException e)
    System.out.println("IO exception caught:");
    e.printStackTrace();
    catch(Exception e)
    System.out.println("Exception caught:");
    e.printStackTrace();

    Hi,
    I have the same problem.
    Is some ORACLE guru that can help us ?
    We need to communicate with some servlet
    via POST method of https (SSL3)
    and with using private certificate on the client site.
    We need furthermore allow using of some proxy.
    Client site is realized as set of stored procedures within ORACLE 8.1.7
    In this time I am able to communicate with server without SSL and certificate
    using package utl_tcp
    (but with this solution without certificate is our customer not satisfied -:))
    ORACLE help us please !
    Pavel Pospisil
    [email protected]

Maybe you are looking for