Java stored procedures connection context

In my Oracle database there are two java stored procedures:
A java stored procedure P1 having
Connection conn1 = DriverManager.getConnection("jdbc:default:connection")
and
a java stored procedure P2 having
Connection conn2 = DriverManager.getConnection("jdbc:default:connection")
P1 calls P2 using conn1.CallableStatement.
Here is the question: does P2 inherit the connection
context conn1 (so that actualy conn2 = conn1) or P2's transactional
scope is separate from P1's one?
Thanks,
-Eugene

AFAIK, when you run Java in the database, for local SQL data access, there is only one default connection per session, P1 and P2 should share the same transaction context.
Kuassi

Similar Messages

  • Java Stored Procedure / connection JDBC / Server Side / Client Side

    Hi,
    I would like to know if we can know at the runtime with a JDBC api if the stored procedure is running in client side or in server side ?
    THANKS

    You wrote
    "Java stored procedures -- by definition - are stored in the 8i rdbms. !!"
    From the Oracle8i Java Stored Procedures Developer's Guide
    Release 8.1.5
    A64686-01
    "If you create Java class files on the client side, you can use loadjava to upload them into the RDBMS. Alternatively, you can upload Java source files and let the Aurora JVM compile them. In most cases, it is best to compile and debug programs on the client side, then upload the class files for final testing within the RDBMS"
    This means that you can create shared classes that are used on both the client and server side. The source does not need to reside within the server (according to their documentation). Please also note the following from the Oracle8i JDBC Developer's Guide and Reference Release 8.1.5 A64685-01 for using the getConnection() method on the server:
    "If you connect to the database with the DriverManager.getConnection() method, then use the connect string jdbc:oracle:kprb:. For example:
    DriverManager.getConnection("jdbc:oracle:kprb:");
    Note that you could include a user name and password in the string, but because you are connecting from the server, they would be ignored."
    So if you're coding a shared class that is to run on both the client and server side, you might do something like this:
    Connection conn =
    DriverManager.getConnection(
    System.getProperty("oracle.server.version") == null
    ? "jdbc:oracle:thin:@hostname:1521:ORCL"
    : "jdbc:oracle:kprb:"),
    "youruserid","yourpassword");
    As stated earlier, the userid and password are supposedly ignored for server connections retrieved in this manner. I haven't tried this yet, but it is documented by Oracle.
    Regards,
    Steve
    null

  • Sending mail in a Java Stored Procedure

    Question: What is the best way to have a Java Stored Procedure connect to our mailhost and send an email? I have been trying to use URL and URLConnection, but I found out URL somehow does not support the "mailto" protocol in the Java Stored Procedure. Funny enough the "mailto" protocol is definetely supported by URL when I test it in the JDK virtual machine.
    Maybe this is the reason: I read in the 8i docs that the 8i Virtual Machine is only JDK1.1.6 compliant.
    Unfortunately I can't find the 1.1.6 docs anywhere. So I cannot do any research on what protocals are supported in JDK1.1.6 .
    Conclusion: Is it possible to send an email in a Java Stored Procedure, and how?
    Thanks in advance :-) Johan

    The Java mail API was a set of extension libraries for the 1.1 JDK. I have heard of folks who succeeded in loading these intot he database and then using them from within a Java stored procedure.

  • APEX fails with Java stored procedure that creates a JDBC connection

    Hello!
    We are facing a strange problem since we have upgraded from Oracle 10g and Apache to Oracle 11g with Embedded Gateway.
    Here is what we do:
    ** APEXX calls a PL/SQL package function "OPEN_CONNECTION" that wraps a Java stored procedure called "openConnection".*
    FILE_READER_REMOTE_API.openConnection(user, password, host, port, service);
    ** The Java stored procedures "openConnection" opens a JDBC connection to an other database:*
    public class FileReaderRemote {
    private static Connection conn = null;
    private static DefaultContext remoteContext = null;
    public static void openConnection(String user, String password, String host, String port, String service) throws SQLException {
    // Load the Oracle JDBC driver
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    java.util.Properties props = new java.util.Properties();
    props.put ("user", user);
    props.put ("password", password);
    //props.put ("database", "//" + host + ":" + port + "/" + service);
    props.put ("database", host + ":" + port + ":" + service);
    props.put("v$session.program", "FileReaderRemote2");
    // Connect to the database
    remoteContext = Oracle.getConnection("jdbc:oracle:thin:", props);
    This procedure used to work fine before the upgrade, but now we see the following:
    * It still works when called directly from TOAD or SQL*Plus, even under the user ANONYMOUS.
    * When called from APEX and the target database is Oracle 11g, it still works.
    * When called from APEX and the target database is Oracle 10g, it takes several minutes and we receive this error:
    *"Socket read timed out"*
    We have tested the following workaround:
    We have created a database link to our own database and called the stored procedure through that database link.
    FILE_READER_REMOTE_API.openConnection*@loopback*(user, password, host, port, service);
    This works, but is not really an option.
    I hope some one of you can explain this strange behaviour to me.
    Best regards,
    Matthias

    You wrote
    "Java stored procedures -- by definition - are stored in the 8i rdbms. !!"
    From the Oracle8i Java Stored Procedures Developer's Guide
    Release 8.1.5
    A64686-01
    "If you create Java class files on the client side, you can use loadjava to upload them into the RDBMS. Alternatively, you can upload Java source files and let the Aurora JVM compile them. In most cases, it is best to compile and debug programs on the client side, then upload the class files for final testing within the RDBMS"
    This means that you can create shared classes that are used on both the client and server side. The source does not need to reside within the server (according to their documentation). Please also note the following from the Oracle8i JDBC Developer's Guide and Reference Release 8.1.5 A64685-01 for using the getConnection() method on the server:
    "If you connect to the database with the DriverManager.getConnection() method, then use the connect string jdbc:oracle:kprb:. For example:
    DriverManager.getConnection("jdbc:oracle:kprb:");
    Note that you could include a user name and password in the string, but because you are connecting from the server, they would be ignored."
    So if you're coding a shared class that is to run on both the client and server side, you might do something like this:
    Connection conn =
    DriverManager.getConnection(
    System.getProperty("oracle.server.version") == null
    ? "jdbc:oracle:thin:@hostname:1521:ORCL"
    : "jdbc:oracle:kprb:"),
    "youruserid","yourpassword");
    As stated earlier, the userid and password are supposedly ignored for server connections retrieved in this manner. I haven't tried this yet, but it is documented by Oracle.
    Regards,
    Steve
    null

  • SQL Server connection in Java Stored Procedures

    Is it possible to establish a connection to microsoft sql server through java stored procedures. When I try to create a connetion to SQL Server I am getting the following exception in trace file
    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
    at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
    at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
    at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(DriverManager.java)
    at java.sql.DriverManager.getConnection(DriverManager.java)
    The connection details are correct and I am able to connect when I run the java code externally. Thanks in advance for the help

    Can you connect to the MSSQL database from inside Oracle in (say) a SQL*Plus or SQL Developer session?
    In other words, is the problem in the Java or the database linkages? Are you using Heterogeneous Services or Transparent Gateways?
    Cheers, APC
    blog: http://radiofreetooting.blogspot.com

  • Java Stored Procedure in one database connecting to muntiple databases.

    Hello,
    I created a Java Stored Procedure in one database(Oracle10g) and successfully open a connection to another database(Oracle10g) using Thin JDBC Driver. I want to actually transfer CLOB data from one DB to another DB. I am concern that by opening a connection another database in Java Stored Procedure, might interfere with oracle and destabilize the instance at some point. Oracle JDBC FAQ (Link: http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#34_13) stated that Yes it could be done but then mentioned the workaround.(if it could be done why do we need a workaround!!!)
    I would like to confirm whether connecting to multiple DB using JDBC Thin Driver in a Java Stored Procedure is supported by Oracle10g or not and whether it has any known issue with it.
    Thanks in Advance!
    Edited by: user649261 on Sep 16, 2008 8:05 PM

    hrishy wrote:
    Thanks i have modified the title so its easy to comprehendWrite the two parts mentioned above and post if you get problems with your code.
    First write code that calls the stored procedure and test that to make sure that it works.
    Then write a simple webservice and test it out to make sure it works. The integration should be trivial after that.

  • Java Stored Procedure / Server Side / Client Side / connection

    Hi,
    I would like to know if we can know at the runtime with a JDBC api if the stored procedure is running in client side or in server side ?
    THANKS

    You wrote
    "Java stored procedures -- by definition - are stored in the 8i rdbms. !!"
    From the Oracle8i Java Stored Procedures Developer's Guide
    Release 8.1.5
    A64686-01
    "If you create Java class files on the client side, you can use loadjava to upload them into the RDBMS. Alternatively, you can upload Java source files and let the Aurora JVM compile them. In most cases, it is best to compile and debug programs on the client side, then upload the class files for final testing within the RDBMS"
    This means that you can create shared classes that are used on both the client and server side. The source does not need to reside within the server (according to their documentation). Please also note the following from the Oracle8i JDBC Developer's Guide and Reference Release 8.1.5 A64685-01 for using the getConnection() method on the server:
    "If you connect to the database with the DriverManager.getConnection() method, then use the connect string jdbc:oracle:kprb:. For example:
    DriverManager.getConnection("jdbc:oracle:kprb:");
    Note that you could include a user name and password in the string, but because you are connecting from the server, they would be ignored."
    So if you're coding a shared class that is to run on both the client and server side, you might do something like this:
    Connection conn =
    DriverManager.getConnection(
    System.getProperty("oracle.server.version") == null
    ? "jdbc:oracle:thin:@hostname:1521:ORCL"
    : "jdbc:oracle:kprb:"),
    "youruserid","yourpassword");
    As stated earlier, the userid and password are supposedly ignored for server connections retrieved in this manner. I haven't tried this yet, but it is documented by Oracle.
    Regards,
    Steve
    null

  • How to get connection of the db lite from java stored procedure?

    Hello! All.,
    I have a written java stored procedures to assign sequence keys, and update some tables. The procedure is working as per our need by using the following connection information.
    try {
    int rowFetched = 0;
    Class.forName("oracle.lite.poljdbc.POLJDBCDriver");
    // connect to the database
    Connection conn = DriverManager.getConnection("jdbc:polite:polite",
    "system", "manager");
    My question is, It is possible in db lite to get a default connections like we use in the enterprise database
    conn = new OracleDriver().defaultConnection();
    Could anybody please shed some light on this.
    Thanks in advance.
    Kathir

    Hello Upi! out of curiosity if you happen to know the answer for the following, I do appreciate it.
    Hello! We are using BC/ADF JClient to select and for any DML operation against Oracle Lite database. We may have more than one user(s) log on to our application, so we requires to authenticate oracle lite user credential using JDBC dynamically.
    I am utilizing the features of JCLoginDialog.java and manipulation bc4j.xcfg file. This work real good for accepting username/password credentials dynamically, since we have multiple database in one computer I have to accept DSN name and if possible built my own configuration file.

  • How can I implement the connection pool in my java stored procedure

    my java stored procedures (in database 'B') have to connect to another oracle database ,let's say 'A'. And how can I implement the behavior like the so-called connection pool in my java stored procedure in 'B', as below.
    1. database B, has 2 java stored procedures sp1 and sp2
    2. both sp1 and sp2 connects to databse 'A'
    whatever I call the sp1 and sp2 and the database 'A' always only one connected session from sp1 and sp2 in database 'B'.
    THANKS A LOTS...

    my problem is I have a lots of java stored procedures need to cnnect to the remote oracle db, and I hope the remote db can only have a connected session from my java stored procedures in my local db. I try as below
    class sp{
    static Connection conn=null; //the remote db connection,
    public static void sp1(){...}//procedure 1, using conn
    public static void sp2(){...}//procedure 2, using conn,too
    I can 'see' the 'conn' variable if I invoke the sp1() and sp2() from the same client application(maybe sqlplus). But if I invoke the sp1() from client 'A' and invoke sp2() from client 'B' then the sp1() and sp2() can not see the 'conn' variable for each other. I think it's because the two clients cause oracle to create two instances of the class 'sp' and the sp1() and sp2() located in different instance seperately. Thus the sp1() and sp2() can not see 'conn' for each other. They can only see its own 'conn'.
    To connect to the remote db from the java stored procedure is easy but is it possible to connect to the remote db via database link from the java stored procedure at my local db ? If so, then I also archive my goal .
    BTW , thanks a lots...
    andrew :-)

  • SSL Connection from a Java Stored Procedure

    Hello.
    I have a Java stored procedure for sending emails, using the JavaMail API. I need to use gmails as the SMTP server. Google requires that emails sent from their servers must be sent through SSL and must be authenticated.
    I'm having trouble in achieving this. Monitoring all traffic sent from the oracle database server, I've noticed that there is a successful connection to google, and a few seconds later the host (where the oracle databse is at), sends a packet telling google to finish the transaction.
    I'm wondering if there is any configuration on this issue that needs to be done, or if it is a known Oracle limitation.
    I'm using oracle 10.2.0.1.0
    Thanks a lot.
    Sincerely,
    John.

    Hello.
    I have a Java stored procedure for sending emails, using the JavaMail API. I need to use gmails as the SMTP server. Google requires that emails sent from their servers must be sent through SSL and must be authenticated.
    I'm having trouble in achieving this. Monitoring all traffic sent from the oracle database server, I've noticed that there is a successful connection to google, and a few seconds later the host (where the oracle databse is at), sends a packet telling google to finish the transaction.
    I'm wondering if there is any configuration on this issue that needs to be done, or if it is a known Oracle limitation.
    I'm using oracle 10.2.0.1.0
    Thanks a lot.
    Sincerely,
    John.

  • Connecting to a non-oracle database (jdbc) from a java stored procedure

    Does anyone know to configure the database to allow a connection to a non-oracle database from a Java Stored procedured, using JDBC?
    Thank you in advance,
    Chris

    Hi Chris,
    I haven't tried it, and these are just some of my thoughts, but I
    think you would need to load the JDBC driver for the other database
    into the Oracle database (using the "loadjava" tool, of-course).
    Then your java stored procedure should be able to instantiate the
    third party JDBC driver and obtain a connection to the other database.
    Hope this helps.
    Good Luck,
    Avi.

  • Connecting to SQL Server and MYSQL from a Java stored procedure

    hope someone can help with this. i'm trying to connect to different databases (My SQL, SQL Server) from a java stored procedure. when invoking from within an oracle 9i database, i get the java exception error -
    "Cannot connect to MySQL server on 135.177.196.75:3306. Is there a MySQL server running on the machine/port you are trying to connect to?java.security.AccessControlException)".
    this store procedure works fine when invoked from outside of oracle. any replies would be greatly appreciated. thanks!

    the correct drivers have been loaded. it works when called from outside of oracle. only when invoking from within oracle do we get the error message "Cannot connect to MySQL server on 135.177.196.75:3306. Is there a MySQL server running on the machine/port you are trying to connect to?(java.security.AccessControlException)". it sounds like a permissions/security/configuration issue - oracle is not allowing access to the machine/port for the MySQL or SQL Server database. appreciate the responses so far.

  • How do we connect to a remote database from a Java Stored Procedure?

    We have a situation where we are not able to use a PSP (PL/SQL server page) to update a remote database using database link in an Oracle8i database. This is a known bug on 8i and is fixed in 9i. Can this be done using PSP calling a Java stored procedure, which in turn connects to the remote database and performs the update. If so, how we do remote connectivity to another database from the current java stored procedure.

    We have a situation where we are not able to use a PSP (PL/SQL server page) to update a remote database using database link in an Oracle8i database. This is a known bug on 8i and is fixed in 9i. Can this be done using PSP calling a Java stored procedure, which in turn connects to the remote database and performs the update. If so, how we do remote connectivity to another database from the current java stored procedure.

  • Error while deploying a Java Stored Procedure using JDeveloper

    Hi,
    I was going thru the Oracle By Example article: "Developing SQL and PL/SQL with JDeveloper". (http://www.oracle.com/technology/obe/obe9051jdev/ide1012/plsqlobe/obeplsql.htm)
    One of the items in this article is - "Creating and Deploying a Java Stored Procedure"
    I was able to create a java class, compile it. Created a deployment profile. created a pl/sql wrapper. While trying to deploy the java stored procedure, I am getting the following error:
    Invoking loadjava on connection 'hr_conn' with arguments:
    -order -resolve -thin
    errors : class package1/mypackage/JavaStoredProc
    ORA-29521: referenced name java/lang/StringBuilder could not be found
    The following operations failed
    class package1/mypackage/JavaStoredProc: resolution
    oracle.aurora.server.tools.loadjava.ToolsException: Failures occurred during processing
         at oracle.aurora.server.tools.loadjava.LoadJava.process(LoadJava.java:863)
         at oracle.jdeveloper.deploy.tools.OracleLoadjava.deploy(OracleLoadjava.java:116)
         at oracle.jdeveloper.deploy.tools.OracleLoadjava.deploy(OracleLoadjava.java:46)
         at oracle.jdevimpl.deploy.OracleDeployer.deploy(OracleDeployer.java:97)
         at oracle.jdevimpl.deploy.StoredProcHandler.doDeploy(StoredProcHandler.java:474)
         at oracle.jdevimpl.deploy.StoredProcHandler.doDeploy(StoredProcHandler.java:361)
         at oracle.jdevimpl.deploy.StoredProcHandler.doDeploy(StoredProcHandler.java:285)
         at oracle.jdevimpl.deploy.StoredProcProfileDt$Action$1.run(StoredProcProfileDt.java:383)
    #### Deployment incomplete. #### Oct 27, 2005 1:38:56 PM
    Appreciate your help on this..

    I am using Jdeveloper 10.1.3 Early Access Version. JDK comes with it. I also have another JDK on my machine (JDK1.4.2_09)

  • Unable to access Custom UDTs returned from a Java Stored Procedure

    Hi,
    I have a UDT in the DB :-
    create type contactrecord as object (
    CN_ID NUMBER(8),
    CN_TITLE VARCHAR2(40),
    CN_FIRST_NAME VARCHAR2(25)
    and this is the corresponding java class ContactDetails.java that maps to this UDT, that I loaded in the Aurora VM.
    package package1;
    mport java.sql.SQLData;
    import java.sql.SQLException;
    import java.sql.SQLInput;
    import java.sql.SQLOutput;
    public class ContactDetails implements SQLData
    private String sql_type;
    private long CN_ID;
    private String CN_TITLE;
    private String CN_FIRST_NAME;
    public String getSQLTypeName() throws SQLException
    return this.sql_type;
    //implementation of readSql
    public void readSQL(SQLInput stream, String typeName) throws SQLException
    sql_type = typeName;
    CN_ID = stream.readLong();
    CN_TITLE = stream.readString();
    CN_FIRST_NAME = stream.readString();
    public void writeSQL(SQLOutput stream) throws SQLException
    stream.writeLong(CN_ID);
    stream.writeString(CN_TITLE);
    stream.writeString(CN_FIRST_NAME);
    //getters and setters for the class vars go here.....
    There is another class A.java that has a java stored procedure/function, which I loaded into the Aurora VM
    Here is the class.
    package package1;
    public class A
    public static ContactDetails returnObject(String name )
         ContactDetails cd = new ContactDetails();
         cd.setCN_ID(1);
    cd.setCN_FIRST_NAME(name);
    return cd;
    Then I declared the call spec for A.returnObject() as
    FUNCTION returnObject(name varchar2) return contactrecord
    AS LANGUAGE JAVA
    NAME 'package1.A.returnObject(java.lang.String) return package1.ContactDetails';
    Then I tried to call the function returnObject through JDBC calls from a class in another VM.
    When I access the object returned by the function, I get a null object.
    Here is the Client code:
    CallableStatement cs = null;
    ResultSet rs = null;
    try
    cs = conn.prepareCall("{ ? = call returnObject(?) }");
    java.util.Map map = conn.getTypeMap();
    map.put("ADMIN.CONTACTRECORD", Class.forName("package1.ContactDetails"));
    conn.setTypeMap(map);
    cs.registerOutParameter(1, OracleTypes.STRUCT, "ADMIN.CONTACTRECORD");
    cs.setString(2, "John Doe" );
    cs.execute();
    ContactDetails cd = (ContactDetails)cs.getObject(1);
    System.out.println("contact first name is:-"+cd.getCN_FIRST_NAME()); //Null Pointer here..cd is null....:(
    if (cs != null) cs.close();
    catch(Exception e)
    e.printStackTrace();
    Although If I try to access the same function from a pl/sql block, I am able
    to access the contactrecord fields.
    What could be wrong ..???
    I could not find any error with the object mapping, as it works perfectly when I interact directly from my VM to the DB,
    without going thru the aurora VM.
    I am using a OCI driver to connect to the DB via JDBC.
    Thanx in advance for any help at all.
    -sk

    Shahid,
    I too have had bad luck in many cases with the automatic translation of Java types to PL/SQL and back. I think the SYS package on the PL/SQL side which handles some of the conversion is DBMS_PICKLER (there are equivalent Java classes which do the same in that world and seem to execute automagically when a conversion is needed). You might want to double-check the data type mappings against the DOC on OTN to make sure they map 1-1. Also make sure the permissions are granted against your objects to whoever is executing them, etc. Very often, I've resorted to passing simple scalar types between the two languages as in some cases the results with complex types are inconsistent.
    Sorry this isn't much help,
    -Dan
    http://www.compuware.com/products/devpartner/db/oracle_debug.htm
    Debug PL/SQL and Java in the Oracle Database

Maybe you are looking for

  • Como identificar se um imposto no B1 é retido na fonte ou não?

    Caros, preciso fazer um relatório demonstrando os valores de impostos retidos na fonte e o valor dos impostos não retidos. Como identifico no B1 que o imposto deve ser retido? Grato

  • Certain PDFs won't open in IE

    I'm having a strange issue with PDF files and IE 6-8 on Windows XP.  My company has a website that can be used to create invoices and receipts for members and display that invoice or receipt on the screen.  When I try to do this from one specific com

  • How to get a minus sign with the cost  field in ALV.

    Hi , How to get a minus sign with the cost field in ALV. The Ouput will be displayed like  Rs -1500 instead of 1500- I can't use concatenate also as i may have to use the sum functionality of ALV . Cheers Sunny

  • Query: XMLPayload vs TextPayload in Module

    Hi Experts,           I'm a newbie to PI/XI. I've just started reading about modules and got a query about the XMLPayload and TextPayload?  Could any of you describe when (in which scenario) to use what (Textpayload or XMLPayload)? Does Textpayload c

  • Please HELP! issue with BULK LOAD in FDM 11.1.2.1

    Please assist with a solution to the following error! See log below ** Begin FDM Runtime Error Log Entry [2011-10-07 13:43:39] ** ERROR: Code............................................. -2147217900 Description...................................... Y