Global variable in servlet & DBPooling questions

Hello guys,
I used to develop PHP/ASP, and am new to servlet. I have been searching around for a solution ...
With Php, we can get the reference of a global variable in any classes->functions...
How do I do this with servlet ?
And second..I have developed the DB class as below... I set the datasource to be static, so it initializes only once. Is it a good idea? How would you like to improve this class? any comments?
package shop.database;
import javax.sql.DataSource;
import java.sql.*;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.log4j.Logger;
import shop.admin.exception.GeneralException;
public class DdManager {
     static protected Logger logger = Logger.getLogger(DdManager.class);
     private String userName = "root";
private String password = "";
private String hostName = "jdbc:mysql://localhost:3306/shop";
private String database="shop";
     static private DataSource ds;     // set this to be static so all threads share the same job in JVM
     private Statement stmt;
     private Connection conn;
     private ResultSet rs;
     private CallableStatement cs;
public DdManager() {}
* setup the data source and return it
     public static DataSource getDataSource(
          String sDrvName,
          String sUserName,
          String sPwd,
          String connectURI) {
          BasicDataSource ds = new BasicDataSource();
          ds.setDriverClassName( sDrvName );
          ds.setUsername( sUserName );
          ds.setPassword( sPwd );
          ds.setUrl( connectURI );
          ds.setMaxActive( 15 );
          ds.setMaxIdle( 10 );
          ds.setMaxWait( 10000 ); // 10 seconds
          return ds;
     * static init of the class
     * this class is will be called only once to initialize the DataSource
     static {
          try {
               Class.forName( "com.mysql.jdbc.Driver" );
               ds = getDataSource(     "com.mysql.jdbc.Driver",
                                        "root",
                                        "jdbc:mysql://localhost:3306/shop" );
               if (ds == null) {
                    String msg = "Connection Pool error";
                    logger.error(msg);
                    throw new GeneralException(msg);
               logger.info("DataSource has been initialized");
          } catch(Exception exception) {
               logger.error(exception.toString());
               try {
                    throw new GeneralException(exception.toString());
               } catch (GeneralException e) {
                    logger.error(e.toString());
     * get the connection from the pool (DataSource)
public void openConnection() throws GeneralException {
try {
     BasicDataSource bds = (BasicDataSource) ds;
     logger.info("NumActive: " + bds.getNumActive() + ", " + "NumIdle: " + bds.getNumIdle());
conn = ds.getConnection();
logger.info("Connection of " + database + " has been established");
} catch(Exception exception) {
     logger.error(exception.toString());
     throw new GeneralException(exception.toString());
* close the connection will actually return the connection to the pool (Must)
public void closeConnection() throws GeneralException {
     initResource();
try {
     if (conn != null){
               conn.close();
               logger.info("Connection of " + database + " has been closed");
} catch(SQLException exception) {
     logger.error(exception.toString());
     throw new GeneralException(exception.toString());
* prepare the calling stmt
public void prepareProcedure(String callStatement) throws GeneralException {
     initResource();
try {
     cs = conn.prepareCall(callStatement);
} catch(SQLException exception) {
     logger.error(exception.toString());
     throw new GeneralException(exception.toString());
* set the pass-in parameter for "String"
public void setParameter(int position, String parameter) throws GeneralException {
try {
     cs.setString(position, parameter);
} catch(Exception exception) {
     logger.error(exception.toString());
     throw new GeneralException(exception.toString());
* set the pass-in parameter for "Integer"
public void setParameter(int position, int parameter) throws GeneralException {
try {
     cs.setInt(position, parameter);
} catch(Exception exception) {
     logger.error(exception.toString());
     throw new GeneralException(exception.toString());
* execute the procedure and return the resultset
public ResultSet execProcedure() throws GeneralException {
try {
     rs = cs.executeQuery();
} catch(SQLException exception) {
     logger.error(exception.toString());
     throw new GeneralException(exception.toString());
return rs;
* close the statment and resultset
     private void initResource() throws GeneralException {
     try {
          if(rs != null) {
               rs.close();
          if(stmt!= null) {
               stmt.close();
          logger.info("Statement & Resultset have been free");
     } catch(Exception exception) {
     logger.error(exception.toString());
     throw new GeneralException(exception.toString());
Thanks mates!
myy

Thanks Saish,
Your response is really appreciated. Sorry about that
as i didnt know there is 'code' formatting button,
and I will look into the Singleton pattern.
As I'm still in the learning stage. Therefore, i
still have a lot of thing do not understand.
... use it in a method signature ...What is "a method signature" ?
A method signature is basically the method's parameters, return value, name and any access or other modifiers. The following is a method signature:
static final public void main(final String[] args)Between the braces of the method body is the implementation (or as I already alluded to, the method body).
Consider using an already-developed connection poolimplementation, such as Jakarta Commons DBCP ...
I'm trying to implement the Jakarta DBCP. Did I go
into the wrong way?
Sorry, did not read the imports. Yes, you are. However, I am confused about what you are trying to implement. You have a static method getDataSource(). You also have a static variable 'ds'. Use one or the other. I would be that there are seemingly random errors cropping up based on whether you remember to call getDataSource() or not.
You do not, generally, want the data source to be static. Multiple threads might use the class. And if there is only a static data source, you will either need to synchronize the methods that use the data source (resulting in a scaling bottleneck) or not synchronize them (which will totally destroy any concept of a logical unit of work or database transaction).
.. A static datasource, as in your class, can onlysafely be used by one thread at a time, potentially
introducing scaling bottlenecks (or race conditions)
in your system ...
So, you mean there is no need for the DataSource to
be static ?
No, in fact, IMO, it should not be. That is why you are pooling. Use instances. The pool will manage the connections and their availabilty for you.
Why are you throwing GeneralException everywhere?Here's a question: can someone using your class (a
caller) realistically be expected to handle a
database exception?
When there is a database error, I just want to stop
the process and redirect the user to an error page. I
will look into the unchecked exceptions. Thanks.
Unchecked exceptions do not need to be declared in a method signature or caught within the method body. Checked exceptions do. As such, an added benefit is that unchecked exceptions de-clutter your code.
In your initResources() method, what happens if theclose() on ResultSet throws an exception
Oh, yes. I'm so stupid.
Now I only have ...
     private static DataSource ds;     // set this to
be static so all threads share the same obj in JVM
     private Connection conn;
     private CallableStatement cs;
private void initResource() throws GeneralException
n {
     try {
          if(cs != null) {
               cs.close();
logger.info("CallableStatement has been
as been free");
     } catch(Exception exception) {
     logger.error(exception.toString());
throw new
throw new GeneralException(exception.toString());
You still have issues.
public void initResources() {
   if (rs != null) {
     try { rs.close(); } catch (SQLException ignore) { ignore.printStackTrace(); }
   if (stmt != null) {
     try { stmt.close(); } catch (SQLException ignore) { ignore.printStackTrace(); }
}Normally, this type of method would not be called initResources() but rather closeResources() or freeResources(). It would be called from within the 'finally' block of another method using the CallableStatement or ResultSet.
This is really is problem, would you mind to tell me
how to handle this(close the connection) if the
close() on either CallableStatement or Resultset
throws an exception ?
See above. Simply log the exception (there is usually nothing meaningful you can do if a close() fails, and it is up to you as a developer if this is an error or just a warning). Another option is to 'chain' exceptions. In your own exception, add a method 'addException(Throwable)'. This would add another exception to a List of exceptions. When you print the stack trace, iterate through the chained exceptions to print them all out. One place where I find this useful is rollback() code. If the original SQL statement fails AND the rollback fails, I definitely want to see that rollback() exception as well in my logs.
The DB thing makes me headache. What I actually
wanted is a solution for:
Let say I have a class "HelloAction.class" contains
the code:
public ActionForward XXX() {
     DbManager DB = new DBManager();
     ... do some DB thing here...
     SecondClass SC = new SecondClass();
     SC.doSomeOtherDbThing();
     ... do something else...
     ThirdClass TC = new ThirdClass();
     SC.doMoreOtherDbThing();
}There are some functions in SecondClass.class and
ThirdClass.class that will need database connection.
I consider 'global variable' is because I want these
two classes are able to use the same
connection(DbManager) from the function -
ActionForward XXX().
What is the best way to implement the above situation
(sharing the same connection in different classes &
sub-classes?
I also just realize that the problem of multi-threads
with these two class variables..
     private Connection conn;
     private CallableStatement cs;Really headache. I really appreciate any comments.
Thanks.
- myyPass the Connection or DataSource to each method or constructor. Call commit() or rollback() from the method that created the transaction.
- Saish

Similar Messages

  • Global variable in servlet

    Dear Friends,
    I have a hashtable(which keeps all user sessions) as a global variable in my login servlet and I have three methods in servlet.
    Hashtable sessiontable = new Hashtable();
    public synchronized void addSession(HttpSession s)
    sessiontable.put(s.getId(), s);
    public synchronized void removeSession(String id)
    HttpSession tempsession = sessiontable.get(id);
    sessiontable.remove(tempsession );
    public synchronized HttpSession getSession(String id)
    return sessionTable.get(id)
    Can u plz help me to figure out whether there will be any synchronization problems.
    Best Rehards,
    Chamal.

    Dear Friends,
    I have a hashtable(which keeps all user sessions) as a global variable in my login servlet and I have three methods in servlet.
    Hashtable sessiontable = new Hashtable();
    public synchronized void addSession(HttpSession s)
    sessiontable.put(s.getId(), s);
    public synchronized void removeSession(String id)
    HttpSession tempsession = sessiontable.get(id);
    sessiontable.remove(tempsession );
    public synchronized HttpSession getSession(String id)
    return sessionTable.get(id)
    Can u plz help me to figure out whether there will be any synchronization problems.
    Best Rehards,
    Chamal.

  • Quick question, where to put global variables

    Very quick question:
    where is the best place to put global variables,
    (e.g. a flag that turns on debug mode)
    if they are needed by the entire application?
    I'm guessing they should be placed in their own class.
    But should I make them public static final constants,
    and just do Globals.MYCONSTANT
    OR should i do "implements Globals" in all my other classes?
    The first way seems simpler and more logical,
    but in the examples for JSDT, they use the second technique.
    Any thoughts?
    thanks! =)

    I would suggest either creating a properties file for your globals, or adding them to the system properties at startup. Placing items like debugging tags in your code means that you have to change the code, recompile, and rejar before your change is implemented. Using system properties means that you simply have to change your command-line options (i.e., from -Dmyapp.debug=true to -Dmyapp.debug=false).
    Shaun

  • Functional global variable question

    Hello,
    I fully understand how a functional global variable (FGV) works and its purpose but I have one last question.
    How do I guarantee (or how is it guaranteed) that my sub-VI (the FGV one) is not re-entrant, in other words, how am I sure that when an instance of the FGV is running it does not loose the processor to others?  Is this an option that I can choose in a sub-VI or is it related to the while loop or case strucure that compose a FGV?
    Joao

    Hi Joao,
    For a little more background on configuring reentrancy and the options you have available if you do want to make a subVI reentrant:
    LabVIEW Help: Reentrancy: Allowing Simultaneous Calls to the Same SubVI
    http://zone.ni.com/reference/en-XX/help/371361K-01/lvconcepts/reentrancy/
    As Lynn said, all new SubVIs will be non-reentrant by default.
    Regards,
    Tom L.

  • Question about global variables in Netbeans 4.1's debugger

    so i can see the local variables, great.
    how do i display the global variables when im debugging? searched help, nothing, searched the netbeans site, nothing.
    anyone know?

    I haven't used the 4.1 version of the debugger (I can't get it to work on a single file/class) but under 3.6 you just put the cursor over them and the values is in the tooltip.

  • Global Variable Question

    I need to create a way for someone to view my LV 6.1 application from another computer. I know there are ways to do this; but I also need for the remote computer to be able to change tab controls to view different sets of data without changing what the local operator is seeing. (I.e. a VNC solution will not work)
     I was thinking that the easiest way to do this might be to just make a duplicate of the program and disable all of the controls I don't want them to be able to use, then just use global variables to pass the live data from the main program to the remote program. Since the remote program will not be able to change the state of any of the globals, there won't be any possibility of race conditions between the two programs. This way I can just pass the status of all of the indicators on the screen to the other program.
    Will this actually work? The two programs will both have to be built into exe files; and will need to be able to run on a PC that only has the run-time environment installed.
    Thanks for your help

    I was originally thinking of using TCP/IP to impliment this functionality, but it seems like it would be simpler to have the main program publish all of its indicators that I want visible to datasocket, then in my remote program have it subcribe to those datasocket items on the main computer. Is this going to cause a major VI slowdown on my main PC I was just going to use the front panel datasocket functionality (i.e. right click and data operations -> datasocket connection)? There are probably 30+ indicators and  some charts/graphs that I want to share between the programs.

  • Global Variables Question

    How do I access varibles from within another function. For
    instance, I load some variables from a txt file and once loading is
    complete I assign some variables. The variables from the oncomplete
    function is the variables I want to use in another function.
    here is an example using a variable that is declared outside
    the function
    Example:
    var variable1:Number = 5;
    var myTimer:Timer=new Timer(1000);
    myTimer.start();
    myTimer.addEventListener(TimerEvent.TIMER, show_variable);
    function show_variable(myevent:Event) {
    trace(variable1);
    The above code works as expected. It traces the variable 5 to
    the output window every second.
    What I want to do is to get the variable from a txt file. The
    example below gets the variable1 from a text file named
    Variables.txt.
    Example:
    var myURLLoader:URLLoader= new URLLoader();
    var myURLRequest:URLRequest = new
    URLRequest("Variables.txt");
    myURLLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
    myURLLoader.load(myURLRequest);
    myURLLoader.addEventListener(Event.COMPLETE, dataOK);
    function dataOK(myevent1:Event):void{
    var variable1:Number=myURLLoader.data.variable1;
    The above code works as expected. But now I want to use
    variable1 in the function below.
    var myTimer:Timer=new Timer(1000);
    myTimer.start();
    myTimer.addEventListener(TimerEvent.TIMER, show_variable);
    function show_variable(myevent:Event) {
    trace(variable1);
    How do I declare it as a global variable or reference it from
    the dataOK function. I tried to declare it as root.variable1 but
    that throws an error. Thanks.

    Thanks. It was just a matter of defining the variable first
    outside the function. Then in the dataOK function changing the
    variables. The changed variables are available for the other
    functions.
    Example:
    var myURLLoader:URLLoader= new URLLoader();
    var myURLRequest:URLRequest = new
    URLRequest("Variables.txt");
    myURLLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
    myURLLoader.load(myURLRequest);
    //Declaring the variables here and setting them to 0
    var variable1:Number=0;
    var variable2:Number=0;
    myURLLoader.addEventListener(Event.COMPLETE, dataOK);
    function dataOK(myevent1:Event):void{
    variable1=myURLLoader.data.variable1;
    variable2=myURLLoader.data.variable2;
    test();
    function test(){
    trace("variable1="+variable1);
    trace("variable2="+variable2);
    I know there is always a simple solution. Just had to wrap my
    head around it the right way. lol! Thanks for the help.

  • Java Threads vs. Native Global Variables

    A brief description of the problem:
    I am trying to integrate a multi-threaded Java app with legacy Fortran code. The Fortran code in question makes extensive use of global variables in the form of Fortran's Common Block data structure.
    If multiple threads were allowed access to a native routine, they would over write each others data which is stored in global variables.
    If only one thread at a time can have access to the native routine for the duration of the native routine, the whole advantage of using threads is completely nullified.
    These native routines cannot be rewritten (3rd party code) and must be used.
    One solution I envisioned was to load a new copy of the native shared object code for each Java object that used the native code. However, it seems System.loadLibrary() can only be used in a static context.
    Is there any known solution to this problem?

    Here is an elaboration on the earlier suggestions. It's a high overhead solution, because you have to start a bunch of JVMs.
    1. You have a java control program, which will start up a pool of "services", make requests to them, and gather the results.
    2. Each service is a small java program with a native method:
    o java communications front-end.
    o native method declaration.
    o native - in your case fortran - method implementation.
    3. Each service is started using "exec". That puts it in a separate process.
    4, Since each service is a java program, you can use java to do communications between the control program and the service.
    o You could use RMI.
    o You could - perhaps - use java Process communications, i.e., have the services write to stdout, and have the control program capture the output.
    o You could use socket communications.

  • Unit Testing and APEX Global Variables

    We've recently started to unit test our database level PL/SQL business logic.
    As such we have a need to be able to simulate or provide output from PL/SQL APEX components in order to facilitate testing of these components.
    Some of the most obvious portions that need simulation are:
    1. The existence of a session
    2. The current application ID
    3. The current page ID.
    We currently handle requirement #1 by using apex_040100.wwv_flow_session.create_new
    We handle 2 and 3 using the apex_application.g_flow_id and g_flow_step_id global variables.
    I'm just wondering, how safe is it for us to use wwv_flow_session.create_new to simulate the creation of a session at testing time for those things which need a session?
    I've also noticed that there are apex_application.get_application_id and apex_application.get_page_id functions whose output is not tied to the global variables (at least in our current version).
    Is it safe for us to expect that we can set these global variables for use in testing or is apex moving to get_application_id and get_page_id functions away from global variables?
    Will there be corresponding set_application_id and set_page_id functions in the future?
    Sorry for the question bomb. Thanks for any help.

    My first question would be why do you need to establish a session to test your PL/SQL?
    wwv_flow_session is a package internal to APEX, and you should probably leave it be.
    The get_application_id procedure you refer to is in apex_application_install, which is used for scripting installation of applications - not get/set of page ID like you're describing.
    If you're uncomfortable using apex_application.g_flow_id, you can use v('APP_ID') or preferably pass the app_id/page_id as parameters to your procedures.
    Your question seems to have a few unknowns, so that's the best I can describe.
    Scott

  • How to Use Transient View Objects to Store Session-level Global Variables

    hi
    Please consider section "40.8.5 How to Use Transient View Objects to Store Session-level Global Variables"
    at http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/bcstatemgmt.htm#ADFFD19610
    Based on this documentation I created the example application
    at http://www.consideringred.com/files/oracle/2010/ProgrammaticalViewObjectAndRollbackApp-v0.01.zip
    It behaves as show in the screencast at http://screencast.com/t/qDvSQCgpvYdd
    Its Application Module has a Transient View Object instance "MyEmployeesContextVOVI", as master for the child View Object instance "EmpInCtxJobVI".
    On rollback the Transient View Object instance keeps its row and attribute values.
    Also when passivation and activation is forced (using jbo.ampool.doampooling=false ) the Transient View Object instance seems to keep its row and attribute values.
    questions:
    - (q1) Why does the expression #{bindings.MyEmployeesContextVOVIIterator.dataControl.transactionDirty} evaluate as true when a Transient View Object instance attribute value is changed (as shown in screencast at http://screencast.com/t/qDvSQCgpvYdd )?
    - (q2) What would be a robust approach to make a Transient View Object instance more self-contained, and manage itself to have only one single row (per instance) at all times (and as such removing the dependency on the Application Module prepareSession() as documented in "5. Create an empty row in the view object when a new user begins using the application module.")?
    many thanks
    Jan Vervecken

    Thanks for your reply Frank.
    q1) Does sample 90 help ? http://blogs.oracle.com/smuenchadf/examples/
    Yes, the sample from Steve Muench does help, "90. Avoiding Dirtying the ADF Model Transaction When Transient Attributes are Set [10.1.3] "
    at http://blogs.oracle.com/smuenchadf/examples/#90
    It does point out a difference in marking transactions dirty by different layers of the framework, "... When any attribute's value is changed through an ADFM binding, the ADFM-layer transaction is marked as dirty. ...".
    This can be illustrate with a small change in the example application
    at http://www.consideringred.com/files/oracle/2010/ProgrammaticalViewObjectAndRollbackApp-v0.02.zip
    It now shows the result of both these expressions on the page ...
    #{bindings.MyEmployeesContextVOVIIterator.dataControl.transactionDirty}
    #{bindings.MyEmployeesContextVOVIIterator.dataControl.dataProvider.transaction.dirty}... where one can be true and the other false respectively.
    See also the screencast at http://screencast.com/t/k8vgNqdKgD
    Similar to the sample from Steve Muench, another modification to the example application introduces MyCustomADFBCDataControl
    at http://www.consideringred.com/files/oracle/2010/ProgrammaticalViewObjectAndRollbackApp-v0.03.zip
    public class MyCustomADFBCDataControl
      extends JUApplication
      @Override
      public void setTransactionModified()
        ApplicationModule vApplicationModule = (ApplicationModule)getDataProvider();
        Transaction vTransaction = vApplicationModule.getTransaction();
        if (vTransaction.isDirty())
          super.setTransactionModified();
    }Resulting in what seems to be more consistent/expected transaction (dirty) information,
    see also the screencast at http://screencast.com/t/756yCs1L1
    Any feedback on why the ADF Model layer is so eager to mark a transaction dirty is always welcome.
    Currently, question (q2) remains.
    regards
    Jan

  • Function module Global variables not cleared from memory?

    Hi,
    This is may be simple & stupid question ( after posting  4242 posts ):)
    " Declaration in TOP
    data : begin of i_y1yatt occurs 0.
            include structure y1yatt.
    data : end of i_y1yatt.
    types: begin of t_yatt71.
           include structure yatt71.
    types: tcode like sy-tcode.
    types: dflag type c.
    types: end of t_yatt71.
    data : i_yatt71 type standard table of t_yatt71
                   with default key  with header line  initial size 0.
    This is code in the function module.
      loop at i_y1yatt.
        move-corresponding o_y1yatt to i_yatt71.
        if i_y1yatt-werks eq 'N501'.
           move space to i_yatt71-werks.
        endif.
        append i_yatt71. 
        " Here this internal contains the previous entry
        clear i_yatt71.
      endloop.
    This function module is called 25 times in a minute.
    My problem is this
    For example : 1st tranmission is called this fm with 50 records,
    and 2nd tranmission is called fm with 10 records.
    My results are showing
    last record in the 1st transmission is still on the memory while calling 2nd transmission.  ( Here in int table I_YATT71 still contains the 1st transmission's last records during the 2nd tranmission call)
    As per my knowledge if each time calls comes in to fm all gloabl variables get cleared. but some how this not happening.
    Anybody come across this scenario.
    PS. I know i need to use clear statement within the loop as first statement.

    You must understand that when calling a FM, you load the entire function group into memory. IF there are global variables, then they are "alive" for the entire duration of the program execution. Meaning if you call the function numerious times, or even if you call another function within the same function group, the functions still have access to that same global variable space, so it must always be cleared manually by the developer at the required points.  You can not rely on the runtime to clear the global variables at the end of the function call.  So you should clear all you globals as the first operation in your function module call, if that is what is required.
    Is this clear?
    Regards,
    Rich Heilman

  • Using functional global variables to transfer data between touch screen device and other targets

    Hi,
    We are currently developing a control system that will operate on a cRIO with a touch screen interface. During development we have been using functional global variables (FGVs) to handle most of the settings/data etc, however we have just realised that we may have an issue updating the data on the touch screen, and vice versa.
    Previously we have implemented similar programs using shared variables, however we were wondering if there is anyway to implement FGVs in a similar manner, whether it'd be a combination of FGVs and shared variables.
    Regards,
    Mike
    Software version: Labview 8.2.1

    See this thread on LAVA about sharing FGV's across projects. THis should be extendable to cross paltforms (I believe).
    You also may want to concider an upgrade to LV 8.5.1. We have found a number of performance related issues with LV 8.2.1 and RT.
    If you decide not to upgrade, just remeber what I wrote (above) when you have reason to question the performance.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Can LabVIEW global variables be shared between UUT sequence steps in the parallel sequence model?

    Sorry for this simple question,  I'm having a hard time finding this answer.
    If I launch a sequence to run on two UUTs in the parallel sequence module,   can I get both UUTs to run LabVIEW vis that use global variables such that :
    1) UUT 0  executes 20 LabVIEW Vi  steps asynchronously,  5 of which access data from LabVIEW global variables A, B, C (Strings)
    2) UUT 0 executes the same 20 LabVIEW based steps asynchronously  5 of which access data from then same LabVIEW global variables A, B, C (Strings)
    I am a little worried that using file globals may have some delays or more of a race condition than using native LabVIEW global variables like in a single labview application perform.  
    QUESTION 2:  Are file globals actually written to the hard drive and shared between parallel sequences through file transfer?  OR  are they in memory?
    Brad Whaley
    LabVIEW Certified Engineer

    Hi bdwhaley,
    Are your parallel sequences only reading from the global variable? Or are they writing to the variable as well? If it is just reading, then you should be okay. File globals are read from memory. Every time they are read, a copy of the data is made in memory.
    Humphrey H.
    Applications Engineer
    National Instruments

  • Setting the value of an Application Item (setting a global variable);

    In APEX 3.2.0.00.27, I need to initialize a global variable to 0 to implement a variable for testing to see if anything on the page has changed. Will update to 1 when certain select lists on the page are changed. Have read through some similar questions and replies within the forum as well as other blogs and sites. So, I believe what I am doing is the way to go about this. Unfortunately, my initialization of an application item/global isn't happening yet. here's a rundown of what has been implemented:
    1) created an application item, G_CLASSIFICATION_ID_NEW in the shared components;
    2) created Javascript (JS) function called by addLoadEvent in the page html header region so when the page loads, the G_CLASSIFICATION_ID_NEW global/application item should get set to 0 with the following JS and using AJAX and htmldb_GET:
    <script type="text/javascript">
    function initVars()
    alert("before get initvars");
    var get = new htmldb_Get(null,$x('pFlowId').value,null,22);
    get.add('G_CLASSIFICATION_ID_NEW', 0);
    gReturn = get.get();
    if(gReturn){
    alert(gReturn.value);
    get = null;
    alert("after get initvars");
    alert("before call to initpage");
    addLoadEvent(initVars());
    </script>
    I've used the htmldb_Get with success for populating other global variables and running On Demand Processes with onchange JS calls in the html form element attributes within select lists on the page. Afterwards, I can check the globals via the Session window and searching on Application Items. Unfortunately, I'm missing something because my G_CLASSIFICATION_ID_NEW never gets populated when I load the page. The alerts all popup when the page is loaded, so I know the script is being executed when the page loads. the alert(gReturn.value) comes back undefined. And, needless to say, the G_CLASSIFICATION_ID_NEW to 0 is not occurring.
    I've tried the htmldb_Get with it calling an application process and without (set to null). From what I've read, you shouldn't need to call an on demand process to have the get.add set the global variable. Then again, this could be where I'm going wrong. however, as I've mentioned, this works for other functions called from an onchange to populate an application item, but the page has already loaded when the onchange(s) get executed. They may work because the page is already loaded when the onchange is called. My point here is that my other On demand processes are NOT setting or changing the global variables at all. The globals are getting set with the get.add(<app item>, <value>) portion of my other JS functions within the HTML Header region. So, I'm inclined to believe that I don't need the 'application_process=<some_odp>' parameter set, but if that's not true, please let me know. if so, what would need to be in the on demand process--ie, what would be the purpose of the get.add(<application item>, <value>) if I set the global variable in the on demand process because that's the only thing I could think of doing within an on demand process for this?
    If somebody can point out what I'm not understanding or failing to do here, that would be great. I'm doing fine with APEX, but wouldn't consider myself a guru with it just yet. I'm definitely not a JS/AJAX guru, and when things like this go astray, I get bogged down because I'm not sure of the problem. So, I'm hoping you gurus who monitor this forum can get me going in the right direction.
    thanks,
    bob

    Hi Jari,
    Does that javascript work if you place it some of region footer on page 22 ?Yes. I cut it out of the html header of the page, and put it in the footer of the first region on the page. It initializes the variable. Putting it into the footer of the first region on the page should work for me instead of having an extra region on the page that's being picked up from page 0.
    Is your page 22 authentication public ?No. This particular page is set for an ADMINISTRATOR only. That said, I am logged in as an administrator. So, I cannot see why setting authentication should make a difference as long as I have that authentication/authorization. Also, there will be other pages where I want to use this script or a similar script, but again, those pages will not be open to the public. the authentication will be "role" based where a user will not necessarily have to be an administrator, but they will have to have a certain role to access the page. Is there a known problem or something that precludes a html header JS script from doing an addloadevent when authentication is NOT public?
    thank you,
    bob

  • How to use a global variable for reading a query resultset in JDBC lookup?

    Hi Friends,
    Using JDBC lookup, I am trying to read from a table Emp1 using a user defined function. In PI 7.0, this function returns values of a single column only even if you fire a " Select * " query. I am planning to use a global variable(array) that stores individual column values of the records returned by a "select *" query. Need pointers on as to how a global variable can be declared and used to acheive the above scenario. Kindly explain with an example. Any help would be appreciated.
    Thanks,
    Amit.

    Hi Amit,
    Sounds like a good idea but then you would need an external db and update the table in a thread safe way !.
    Regarding your question as to how to work with global variable please refer https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/1352. [original link is broken] [original link is broken] [original link is broken]
    Rgds
    joel

Maybe you are looking for

  • IPhoto 6 or other program - recommendations please

    I'm looking for some feedback on iPhoto 6. I have a lot of photos(a lot) now separated into various libraries and am looking to upgrade my photo program from iPhoto 5. My biggest complaint about iPhoto5 was that my library melted down and all of my d

  • I cannot receive MMS over WiFi- anyone else struggling? (2nd post)

    Original post:      I cannot receive MMS over WiFi- anyone else struggling? Apparently, it's not the settings. Tech told me I need to just return the phone b/c they don't have a clue what's wrong with it. They've done everything they can on their end

  • XBOX 360 using MacBook Pro monitor

    Is it possible to play XBOX 360 by connecting it to the MacBook Pro? If possible, could someone please tell me how? Thanks

  • Problem in Date format display at table leve in 3.1i System

    Hi Team, I am facing an issue in 3.1i Prod System. When i go and check at SE16 transaction and table name is TCURR. Execute the same i am getting date displayed in an unknown format. For Eg: Valid From Date 79908769 When i double click the same recor

  • Upgrade NI Configurator version from 3.2 to 3.2.3

    Hello, I upgrated my NI Configurator version from 3.2 to 3.2.3. Now , when a FF device is coming through the bus which is imported per EDD the Configurator crashes. When the device is imported per a simple DD everything works fine. In Version 3.2 als