Cx_oracle objects in python cgi session

Hi,
I am trying some web pages using python cgi and using cx_oracle for data retrieval.
The page fetches many records and I wanted to display 10 records only at once.
So I tried to save the cx_oracle connection obj and cursor object in session variable. but session variable is not supporting to save those variables. :(
How do you guys do this? I dont want to connect and disconnect database every time. any method of doing this?
I am new to web programming, but good in pl/sql.
thanks
~Gouri

This isn't possible with a stateless web model in your scenario. Even with a web-savvy language like PHP which allows "persistent connections" you have to re-execute the query each time you "page". This will see any new data other users have inserted.
You'll need to rethink how the application will be used to see if the paging model will be OK.
Also make sure the infrastructure can cope with frequent connections. (PHP with Oracle 11g connection pooling is a good alternative)

Similar Messages

  • [Solved] Python CGI - how to "include" like in PHP

    Hi.
    When I code PHP I like to use this template system. A short instance would consist of 2 files: "index.php" and "template.php".
    template.php:
    <?php
    echo "<h1>$header</h1>";
    echo "<p>$text</p>";
    ?>
    index.php:
    <?php
    $header = "this is a header";
    $text = "this is a text";
    include "template.php";
    ?>
    So I can use one template for lots of pages - same layout but different vars.
    I cannot find how to do this in Python CGI.
    page.cgi:
    #!/usr/bin/python
    import os, cgi
    x = "This is the page text."
    eval(open('template.cgi').read())
    template.cgi
    print("Content-type: text/html\n")
    print(x)
    This gives me error 500. I am not surprised, this mail.python.org page says:
    > I can't figure out how one would approach this in Python (i'm using
    > mod_python). There's no equivalent to the "include" function from
    > PHP.
    Correct, the concept doesn't exist because you are working
    with vanilla CGI rather than server scripting.
    But maybe there is a way to make something similar?
    Last edited by Mr. Alex (2012-06-05 17:52:42)

    Template (index.html.tpl)
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Main Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
    h1 {{
    margin: auto;
    </style>
    </head>
    <body>
    <h1>Admin</h1>
    <ul>
    <li><a href="{}">Monthly Report</a></li>
    <li><a href="{}">Inventory Zip Files</a></li>
    <li><a href="{}">Order Reports</a> -- Last 7 days</li>
    <li><a href="{}">Notes/TODO/Information</a></li>
    <li><a href="{}">EDI Orders</a></li>
    </ul>
    </body>
    </html>
    index.py :
    #!/usr/bin/env python2
    def main():
    template = "index.html.tpl"
    pages = ("monthly", "zips", "reports", "vimwiki", "edi.py")
    sitename = "/"
    pages = ["{}{}".format(sitename, pages) for i in pages]
    tpl = "".join(open(template,'r').readlines())
    print 'Content-type: text/html\n\n' + tpl.format(*pages)
    if __name__ == '__main__':
    main()
    Maybe not the best way...but it works for me Notice the double {{ }} in the template where you want literal brackets, not placeholders.
    Scott

  • Is it possible to restrict the object creation for stateless session beans

    Hi,
    Is it possible to restrict/fix the ejb object creation for stateless session beans in application server?
    For example, i want to configure the application server ( am using JBOSS ) to create maximum of 10 session bean objects. and if any requests for the stateless session bean come, as application server has created 10 objects, the requests should be blocked.
    Thanks in advance,
    nvseenu

    You can keep a counter in the application code. A static var won't work, but an entity and a consistent id should. This version would affect performance, but it would be portable to other app servers.
    // ConstrainedBean.java
    package unq.ejb;
    import javax.ejb.Stateless;
    import javax.ejb.CreateException;
    import javax.annotation.PostConstruct;
    import javax.annotation.PreDestroy;
    import javax.persistence.PersistenceContext;
    import javax.persistence.EntityManager;
    @Stateless
    public class ConstrainedBean implements Constrained {
        final static int DEFAULT_COUNTERID = 1;
        @PersistenceContext EntityManager em;
        @PostConstruct
        protected void init() throws CreateException {
         ConstrainedBeanCounter counter =
             em.find(ConstrainedBeanCounter.class, DEFAULT_COUNTERID);
         if( counter == null ) {
             counter = new ConstrainedBeanCounter();
             counter.counterId = 1;
             counter.counterValue = 0;
             em.persist(counter);
         if( counter.atMaximum() ) {
             throw new CreateException("error attempting to create > 10 beans");
         else {
             counter.increment();
        @PreDestroy
        protected void destroy() {
         ConstrainedBeanCounter counter = em.find(ConstrainedBeanCounter.class,
                                   DEFAULT_COUNTERID);
         counter.decrement();
        public void doSomething() { System.out.println("doSomething()"); }
    // ConstrainedBeanCounter.java
    package unq.ejb;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    @Entity
    public class ConstrainedBeanCounter implements java.io.Serializable
        @Id public int counterId;
        public int counterValue = 0;
        public void increment() {
         counterValue++;
        public void decrement() {
         counterValue--;
        public boolean atMaximum() {
         return counterValue > 9;
    }

  • CKPT locks the system objects and blocks other sessions

    CKPT locks the system objects and blocks other sessions
    Oracle Version 10.2.0.4
    OS : HP UX 11.31 Itanium
    SQL> select * from v$lock where block=1;
    ADDR KADDR SID TY ID1 ID2 LMODE
    REQUEST CTIME BLOCK
    C0000009FCC2B348 C0000009FCC2B368 1100 RO 65559 1 2
    0 3877 1
    SQL> select program from v$session where sid=1100;
    PROGRAM
    oracle@ctqanhr1 (CKPT)
    As a workaround we flush the buffer cache with the below command
    SQL> alter system flush buffer_cache;
    however the issue reoccurs after some times.
    Edited by: 965132 on Dec 2, 2012 9:59 PM

    other reference:
    CKPT Questions
    The temporary workaround is to set "_db_fast_obj_truncate"=FALSE in that particular case.
    Regards,
    sgc
    Edited by: Samuel G. Cristobal on 03-dic-2012 8:48

  • How can I replace the Python cgi script with CF

    I am testing the sample app and want to just use CF to track
    peer ids.
    Can you give me the api to the web service calls.
    I can then create the CFC to handle this.
    In order to use the sample application that you built, you
    need to setup your web server and host the provided Python script
    (reg.cgi) for exchanging peer IDs. Please note that setting up the
    web service is not needed for the hosted VideoPhone sample. In
    VideoPhoneLabs.mxml, please set WebServiceUrl accordingly. You may
    also use Google Apps to host this web service (minimal
    modifications required).
    The Python script should be placed in the cgi-bin location
    according to your web server installation. The database is an
    SQLite3 database. In reg.cgi, please edit the location of the
    database in variable dbFile.
    You also need to create a database scheme using the
    followings:
    CREATE TABLE registrations (
    m_username VARCHAR COLLATE NOCASE,
    m_identity VARCHAR,
    m_updatetime DATETIME,
    PRIMARY KEY (m_username)
    CREATE INDEX registrations_updatetime ON registrations
    (m_updatetime ASC);

    the sample web service we provided has the following API:
    to record peerID "1234" for username "foo", do
    http://your.domain/cgi-bin/reg.cgi?username=foo&identity=1234
    you should get back an XML document with result.update=true
    or false depending on whether the database was updated.
    to look up the peerID for username "foo", do
    http://your.domain/cgi-bin/reg.cgi?friends=foo
    you should get back an XML document like:
    <?xml version="1.0" encoding="utf-8"?>
    <result>
    <friend>
    <user>foo</user>
    <identity>1234</identity>
    </friend>
    </result>
    there will be no "identity" entry if the user is not found.
    the lookup is case-insensitive but case-preserving, so if you
    looked up "Foo", the user field would be "Foo" but there'd be an
    extra "registered" field with the username as it was registered.
    -mike

  • Problem identify OBJECTS access for a session

    Hi when a try to see what object is take to determined session the database hands consult and close conections. The select clause is "select OBJECT from v$access where SID=<NUM>", this sentence consuming big cpu time, all system have a high numer of the synonyms (23299).
    Why i can't get result this simple select?

    I am not licensed for AWR so I cannot tell you what to post; however, if the report is anything like statspack I would start by just posting the ratio and top waits on the first page or two providing you do not see any statistic that appears to be of interest. If you find something of interest I would try to find the related information and confine the post to that. Based on responses you can post more.
    I see from what you posted that your system appears to be using the PQO option. Make sure you are not overloading Oracle by trying to run an excessive number of PQO processes concurrently. PQO is brute force tuning and does not scale well, that is, the feature was not desiged for use on concurrent SQL.
    I have trouble reading unalligned numbers and I no longer tune databases very often but your reloads number appear high for the other values presented. Is the application written using bind variable or is it stringing together SQL with constant values and passing in new SQL all the time? If the application is using bind variables then the high reloads might indicate that the shared pool is too small forcing Oracle to flush SQL that it will later rerun too often.
    There are some shared pool sizing scripts on metalink you might want to run. The scripts over-estimate space requirements but can ball-park you in.
    From the information presented that is all that comes to mind.
    HTH -- Mark D Powell --

  • RMI server object lookup in a session bean

    Hi all,
    I am getting MarshalException when I call java.rmi.Naming.lookup() in a session
    bean. Following is the code and exception. Please note that I am using java.rmi
    package instead of weblogic.rmi and that both the session bean and RMI server
    object (a startup class) is deployed on the same machine.
    Thanks for your help in advance.
    // a simple, replica-aware session bean method
    // some code here
    try {
    MediatorInterface mediator = (MediatorInterface) java.rmi.Naming.lookup("rmi://localhost:7001/TestMediator);
    catch (Exception e) {
    // log the exception
    The exception:
    java.rmi.MarshalException: Error marshaling transport header; nested exception
    i
    s:
    java.io.EOFException
    java.io.EOFException
    at java.io.DataInputStream.readByte(DataInputStream.java:224)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:206
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:174)
    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:318)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at java.rmi.Naming.lookup(Naming.java:84)
    at test.mgmtop.CreateNetworkOpHandler.execute(CreateNetworkOpHandler.jav
    a:88)
    at test.mgmtop.CreateNetworkOpHandler.perform(CreateNetworkOpHandler.jav
    a:28)
    at test.ejb.MgmtServiceBean.create(MgmtServiceBean.java:57)
    at test.ejb.MgmtServiceSession_idi8yo_EOImpl.create(MgmtServiceSession_i
    di8yo_EOImpl.java:46)
    at test.ejb.MgmtServiceSession_idi8yo_EOImpl_WLSkel.invoke(Unknown Sourc
    e)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:346)
    at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
    ef.java:114)
    at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:300)
    at weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
    eManager.java:762)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
    a:295)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
    .java:30)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:152)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:133)

    Hi Pyung,
    How about trying this instead:
    InitialContext ctx = new InitialContext();
    MediatorInterface mediator = (MediatorInterface) ctx.lookup("TestMediator");
    This assumes your startup class binds the Mediator to the JNDI name "TestMediator".
    - Matt
    Pyung Yoon wrote:
    Hi all,
    I am getting MarshalException when I call java.rmi.Naming.lookup() in a session
    bean. Following is the code and exception. Please note that I am using java.rmi
    package instead of weblogic.rmi and that both the session bean and RMI server
    object (a startup class) is deployed on the same machine.
    Thanks for your help in advance.
    // a simple, replica-aware session bean method
    // some code here
    try {
    MediatorInterface mediator = (MediatorInterface) java.rmi.Naming.lookup("rmi://localhost:7001/TestMediator);
    catch (Exception e) {
    // log the exception
    The exception:
    java.rmi.MarshalException: Error marshaling transport header; nested exception
    i
    s:
    java.io.EOFException
    java.io.EOFException
    at java.io.DataInputStream.readByte(DataInputStream.java:224)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:206
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:174)
    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:318)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at java.rmi.Naming.lookup(Naming.java:84)
    at test.mgmtop.CreateNetworkOpHandler.execute(CreateNetworkOpHandler.jav
    a:88)
    at test.mgmtop.CreateNetworkOpHandler.perform(CreateNetworkOpHandler.jav
    a:28)
    at test.ejb.MgmtServiceBean.create(MgmtServiceBean.java:57)
    at test.ejb.MgmtServiceSession_idi8yo_EOImpl.create(MgmtServiceSession_i
    di8yo_EOImpl.java:46)
    at test.ejb.MgmtServiceSession_idi8yo_EOImpl_WLSkel.invoke(Unknown Sourc
    e)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:346)
    at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
    ef.java:114)
    at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:300)
    at weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
    eManager.java:762)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
    a:295)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
    java:30)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:152)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:133)

  • Passing objects to a servlet - session or as byte[]

    Hi
    I'm creating my first servlet and I want opinions on my design. I plan to sue my servlet to generate an image. So in my jsp page I have an image tag with the following
    <img src="/Servlet/GenerateImage">But my servlet requires data in an ArrayList from my JSP page. How can I pass the ArrayList to my servlet? I've done some research and been looking aorund the forums, and I noticed people either convert the object to byte[] or pass the object using the session. I've tried doing the byte[] method but I don't know how to pass the byte[] to my servlet. I tried passing it as a parameter using a query string, get the parameter as a string, and convert it to byte[] again, but it didn't work. I can't seem to get this approach to work.
    I'm worried that if I use the session, and a large number of people access my page which runs the servlet, my server will be bogged down.
    What is the best approach in doing this? It'd be great if some sample code or links are supplied
    Thanks for all the help!

    My servlet requires data in an ArrayList from my
    JSP page. How can I pass the ArrayList to my servlet?
    I've done some research and been looking aorund the
    forums, and I noticed people either convert the object
    to byte[] or pass the object using the session. If the ArrayList is derived in the JSP and is required in the servlet, then saving it as a session attribute is the best bet. I guess it would be possible to send all the data from the ArrayList to the client in a cookie, but that seems messy and inefficient.
    I'm worried that if I use the session, and a large
    number of people access my page which runs the
    servlet, my server will be bogged down.The session attribute only contains a reference to the ArrayList and so in itself does not cause a performance problem. If you're concerned that the ArrayList is very large, you could consider saving the info to a disk file. Alternatively, could the ArrayList be derived in the servlet instead of, or as well as, the JSP? Does the servlet need all the Arraylist entries, or just a subset? If a subset, save that as a session attribute and dereference the ArrayList in the JSP. Also, think about when the ArrayList reference can safely be removed from the session.
    What is the best approach in doing this? It'd be great
    if some sample code or links are suppliedJSP
    <jsp:useBean id="myArrayList" class="java.util.ArrayList" scope="session"/>Servlet
    HttpSession session = request.getSession();
    ArrayList al = (ArrayList) session.getAttribute("myArrayList");
    .

  • Global object visible for all sessions in WebDynpro application

    Hello everybody,
    in a normal java web application you have the possibility
    to put an object into the servlet context.
    This object is visible for all sessions(e.g. some configurations or global settings for the
    web application).
    Now my question:
    Is there a possibility in a WebDynpro application to put such an object into a "global context" visible for all sessions?
    So I am looking for a container in WebDynpro which has
    the same behaviour like the servlet context in a web application.
    Thank you for your ideas an suggestions.
    Greetings
    Anton

    Hi Anton,
    To make an Variable Global ,you have define variable at various levels based on Usage.
    1)Ex: If you want to define Variable between two different Components . when A component is embedded into B Component then you have to define at Component Interface level and Mapping has to be Defined.
    2) If you want to make Variable to be used within the component among the Iviews ,then you can define at Component Controller or Custom Controller and Mapping has to be defined at Iview Level.
    3) If you want to use Variable between two Webdynpro Iviews then you have define the eventing mechanism to pass the values among the EP Webdynpro Iviews.
    Hope this answer helps you.
    Thanks
    Madhan

  • XmlManager.getDbEnv () returns not-DbEnv object in Python

    I'm trying to retrieve the DbEnv object and use it, but
    XmlManager.getDbEnv ().get_mp_mmapsize () trows an error:
    'PySwigObject' object has no attribute 'get_mp_mmapsize'
    What is the proper way to get DbEnv object?

    I'm trying to retrieve the DbEnv object and use it, but
    XmlManager.getDbEnv ().get_mp_mmapsize () trows an error:
    'PySwigObject' object has no attribute 'get_mp_mmapsize'
    What is the proper way to get DbEnv object?XmlManager.getDbEnv() works. I just checked and the DbEnv interface does not appear to include get_mp_mmapsize in Python.
    Regards,
    George

  • Retrieving All Objects From Session

    I'm developing a JSP shopping cart application, i have problem with sessions. A user can add a product to their cart, this adds the product name and the product price to the cart using:
    <%
    session.setAttribute("pname", pname);
    session.setAttribute("pprice", pprice);
    %>
    The problem I have is viewing the cart. The page must display all items the user has added to the cart. I need to retrieve all the objects from the users session.
    session.getAttribute("pname") will only return the last object which was added to the session. Is there a method or mechansim to loop through all the objects in a users session?
    Any suggestions appreciated.

    session.getAttribute("pname") will only return the
    last object which was added to the session. Is there a
    method or mechansim to loop through all the objects in
    a users session?You can't use session.setAttribute("pname",pname); repeatedly. Each time it will overwrite contents of existing attribute. Thats the reason why you are always getting last added value.
    You can do one thing. Add pname to the Vector or Hashtable, like this,Vector v = (Vector) session.getAttribute("pname"); // Get the existing Vector in the session.
    if(v == null) v = new Vector(); //If there is no attribute "pname" in the session, create an object of Vector.
    v.add(pname) //add item to the Vector.
    session.setAttribute("pname",v); //Now add this vector to the session.Hope this helps.
    Sudha

  • Reference to Object located in timed-out session

    Hello forum!
    I have searched but couldn't find eny answer to following problem:
    I'm developing a web application (struts & Co.) that communicates with different processes.
    Situation:
    In struts action I'm getting some object from session (that I have put there)
    and giving as a parameter to some process P that changes some attributes of this object. I am showing these changes ("interactively") on JSP (e.g. user clicks F5 to see them dynamically).
    The question is, what happens when that process lasts longer then my session timeout? Gets it null on some try or what happens at all?
    Hope I've explained the problem correctly.
    Thanks in advance.

    Thanks for reply!
    It seems I haven't explained the problem correctly. I've checked it - there happens nothig(no null).
    The process has got the object that is in session, not session object itself. So it has no idea what happens in session and after session is dead it is working for nothing... My session will never find out what has happend with that object...
    Thanks a lot.
    gio.

  • How to putput a property of an object in session? (jsp/struts)

    Guys,
    I have an object (myGroup) that consist of 2 properties: groupName and groupTitle. The object is in a session called group_session.
    On my jsp page, I would like to output the property groupName on the text field associated with the groupName:
                   <html:text      property="name"
                                                   value=???????????????
                                  size="45"
                                  maxlength="60" />
                                  <html:errors property="name" />Q: how can I output the value of the groupName in the value section?
    thanks

    Hi
    you can try something like this....
    <input type="text" name="any" property="<bean:write
    name="myGroup" property="groupName "
    scope="session"/> " >
    This snippet is closer to JSP coding rather than struts. Leverage the capabilities of struts by setting the values in ActionServlet instead.
    <html:text property="name" size="45"  maxlength="60" />                    -Rohit
    By the way why did you add this tag
    <html:errors property="name" /> ??
    Message was edited by:
    RohitKumar

  • Session State Replication of Referenced Objects

    Here is question on Clustering and Session state replication:
              Scenario:
              Consider two Session Objects A and B.
              Object A has-a reference to object B.
              So whatever changes done to Object B is reflected in Object A.
              In-memory Session replication happens on every HttpSession.setAttribute() call.
              The question is will the two session objects(A and B) be replicated to the other cluster and will still maintain the reference relationship or will they be two separate objects with same data (in different memory locations).
              regards,
              Jaiganesh

    Ok, I have been meaning to dig into session replication in a bit more detail and your question is a good excuse to do it!
              First stop the docs:
              Bea Docs
              The bits that jump out are under:
              Programming Considerations for Clustered Servlets and JSPs
              1) Session Data Must Be Serializable, so both your objects are serializable.
              2) Use setAttribute to Change Session State In an HTTP servlet that implements javax.servlet.http.HttpSession, use HttpSession.setAttribute (which replaces the deprecated putValue) to change attributes in a session object. If you set attributes in a session object with setAttribute, the object and its attributes are replicated in a cluster using in-memory replication. If you use other set methods to change objects within a session, WebLogic Server does not replicate those changes. Every time a change is made to an object that is in the session, setAttribute() should be called to update that object across the cluster.
              Likewise, use removeAttribute (which, in turn, replaces the deprecated removeValue) to remove an attribute from a session object.
              >Will the reference as shown in the step 3 will be >maintained after replication on the other cluster ?? I >guess not!!
              I don't understand "on the other cluster" There is normally one cluster made up of a few servers. The session state is maintained on one primary server and a secondary server. So you have aObj.a2 = bObj, from the docs I would understand that at the momment you called session.setAttribute the aObj and all its fields provided they are seriliazable will be replicated in Mememory.
              >There the aObj and bObj stored in the two different >session objects will not have a reference relationship >in other words if i change bObj on the other cluster >will the reference a2 of aObj be able see it ??
              This is testing the limits of my understanding, but would have thought if the objects are in different sessions they should not be able to reference each other in the manner I think you are suggesting, so if I access aObj.a2 (an instance of bObj) and changed it in one session it should not affet any other bObj unless bObj is a singleton....I think!
              What say you?

  • How to use session object in windows application

    hi, I am programming in jdeveloper. i need to know that while i m making a web application i can use a session object for the particular session. now i m builiding a windows application for my final semester and i need to insert product id and then it should go to another frame and there it can store multiple information for a particular product id.
    e.g
    product id : 001
    next frame.
    filter name.
    filter position.
    when these are added then it should be able to add more filters for the same product id and i dont understand how to do that.
    Please let me know as i am lost and dont know how to proceed further. if some body wants to have a look on the codes he is most welcome.
    Waiting for an answer
    thank you

    Hi,
    in Swing applications you don't have a session object to store data. You can use a helper class though to act as a temporary memory. Just create a static class that has a hashtable method to add / read / remove data
    Frank

Maybe you are looking for