How to load value to a static variable on the run

hi all
i have a question about static variable. i need to have a variable to keep a value from DB shared by all instances. the variable is given value when the first instance is created. but from time to time, the value in DB may change, but i still need to maintain this shared value among instances. the static variable has life time as long as the program runs, does that mean if i need to change the value, i need to stop the program, and restart to load the new value? thanks.

can the static variable be accessed within a
non-static method, for instance, set the value by
setXXX() method?Yes, and oddly enough, that usually how I access all my variables...
Example...
public class StaticTester {
       static String theString = " My Message ";
       public void setMessage(String mess){
                  theString = mess;
       public String getMessage(){
                  return theString;
       public static void main(String[] theArgs){
                  StaticTester myTest = new StaticTester();
                System.out.println(myTest.getMessage());
                myTest.setMessage(" a New Message ");
             System.out.println(myTest.getMessage());
}Hope this helps...
- MaxxDmg...
- ' He who never sleeps... '

Similar Messages

  • How to give different value to a static variable???

    Hi all:
    Is there any solution to set different values to a static variable???I had try two ways but all have errors!
    1.Way_1
    protected String tmp=null;
    protected void initSituation(int sayorpress)
    if (sayorpress==0)
    tmp = "string1";
    else if (sayorpress==1)
    tmp = "string2";
    protected static String RESOURCE_STRING = tmp; <---error
    Error:non-static variable tmp cannot be referenced from a static context
    2.Way_2
    protected void initSituation(int sayorpress)
    if (sayorpress==0)
    protected static String RESOURCE_STRING = "string1"; <---error
    else if (sayorpress==1)
    protected static String RESOURCE_STRING = "string2"; <---error
    Error:illegal start of expression at
    not an expression statement at
    Thank you very mich!!!

    Try this:
    protected static String RESOURCE_STRING = null;
    protected void initSituation(int sayorpress)
    if (sayorpress==0)
    yourClass.RESOURCE_STRING = "string1";
    else if (sayorpress==1)
    yourClass.RESOURCE_STRING = "string2";
    You cannot declare a static variable inside a method. But you can access a static variable thorugh your class.

  • My friend synced a video to my ipod but it erased all my data on my ipod,but i cant figure out how to load my old libray back without deleting the movie. my friend cant tell me the password. How can I get my old library back without deleting the movie?

    My friend synced a video to my ipod but it earased all my data on my ipod,but I can't figure out how to load my old library back without deleting the movie. My friend shares a family account so she can't tell me the password. How can i get my old library back without deleting the movie?

    Linnwarner wrote:
    She does have the right because she bought the movie.
    Not true at all.
    You only buy the right to your own personal use.
    You do NOT have the right to distribute to others.
    This is illegal.  There is no doubt about it

  • DB2Exception - The value of a host variable in the EXECUTE or OPEN statemen

    I want to store a XML file into database.
    To undersdande my problem, please see the code below:
    java.sql.Connection conn = null ;
    PreparedStatement ps;
    // Here I'm calling a function to get Database Connection.
    String sXmlFile = "" ; // This variable stores a XML file as String
    String sSQL = "INSERT INTO Crs_x_xml (XML_TRAN_ID,XML_MESSAGE,SUSPENDED_FLAG ) VALUES(?,?,?)";
    try {
         ps = conn.prepareStatement(sSQL);
         ps.setLong(1,1);
         ps.setBytes(2, sXmlFile.getBytes());
         ps.setString(3,"A");
         ps.executeUpdate();
         conn.close();
    } catch (Exception e) {
         e.printStackTrace();
    The Problem:
    The table Crs_x_xml that I used has three columns, the first is a int, the second is a BLOB and third is Char(1) and its in DB2 running on AIX.
    Sometimes it execute very well. But sometimes gives following error :=
    COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/AIX64] SQL0302N The value of a host variable in the EXECUTE or OPEN statement is too large for its corresponding use. SQLSTATE=22001
    I dont know whats going wrong. Plz help....
    ~Abhijeet

    Hi,
    I am using a CMP query in websphere, in which i am trying to execute a select query.
    The query is as follows:
    SELECT OBJECT(o) FROM HrTmmbrAct o WHERE o.tmmbrActC IN ( 1,2,3 ) AND o.effD BETWEEN '2000-02-11' AND '2008-02-22'
    The tmmbrActC is defined as a string in the Websphere CMP fields. I am not sure now to pass the value to it. Do we need to pass it as objects. pls help.
    Thanks
    - Giri

  • Does anyone know how to load ACR presets when using ACR in the creative cloud?

    Does anyone know how to load ACR presets when using ACR in the creative cloud?

    Moving the discussion to Adobe Camera Raw forum.
    Thanks,
    Atul Saini

  • How to load  2 records out of 4records to the  datasource....

    how to load  2 records out of 4records to the  datasource....

    Hi
    when you execute the Infopackage of the datasource, restrict the selection screen to only those 2 records
    Regards

  • How to load values from database into the f:selectItems value attribute

    Hi,
    I am trying to load the drop down menu value i.e f:selectItems from the database with a list of values from a column in the databse table. how can i do this? Should i use binding? or is there any other way.
    Note:i am able to load values into f:selectItems from the faces-config.xml file but they are static values. i want the values from the database
    Please reply with sample codes of faces jsp, bean file and config.xml file

    But this is working for me,
    JSF
         <h:selectOneMenu value="#{loadbean.grade}" >
              <f:selectItems value="#{loadbean.gradelist}" />
         </h:selectOneMenu>
    bean
    private String grade;
    private List<SelectItem> gradelist;
    public String getGrade() {
              return grade;
         public void setGrade(String grade) {
              this.grade = grade;
         public List<SelectItem> getGradelist() {
              return gradelist;
         public void setGradelist(List<String> items) {
              gradelist=new ArrayList<SelectItem>();
              gradelist.add(new SelectItem("daniel"));//this value can be from data base
              gradelist.add(new SelectItem("pspindia"));
              gradelist.add(new SelectItem("prelude sys"));
    faces-config.xml
    <managed-property>
              <property-name>gradelist</property-name>
              <null-value/>
    </managed-property>
    this working fine for me. So setter method also works to load value for the h:selectItems
    Thanks a lot.

  • How to load a unknown number of variables?

    Hi!
    I'm trying to load a known number of variables. So I set up this code in flash:
    //Laddar pris och namn********************************
    var loader:URLLoader = new URLLoader();
    // specify format as being variables
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.addEventListener(Event.COMPLETE, varsLoaded);
    // vars.txt contents:  foo=bar&foo2=bar2
    loader.load(new URLRequest("http://gbgknappen.se/designitonline/dekaldesigner/load_pris.php"));
    function varsLoaded (event:Event):void {
              var string_produkter="";
              var whilecount=0;
              while(loader.data.antal>whilecount){
                        var produkt_load="produkt_"+whilecount;
              trace(loader.data.produkt_load);
                        whilecount=whilecount+1;
         pris_ruta.text=string_produkter;
    It recive "antal"which is how many variables there are. The variables name are named produkt_0 produkt_1 produkt_2 produkt_3 and so on..
    so

    function varsLoaded(event:Event):void
    var loops:uint = loader.data.antal;
    for (var i:uint=0; i<loops; i++)
      trace(loader.data["produkt_"+i]);

  • How to reference a static variable before the static initializer runs

    I'm anything but new to Java. Nevertheless, one discovers something new ever' once n a while. (At least I think so; correct me if I'm wrong in this.)
    I've long thought it impossible to reference a static variable on a class without the class' static initializer running first. But I seem to have discovered a way:
    public class Foo  {
      public static final SumClass fooVar;  // by default initialized to null
      static  {
         fooVar = new SumClass();
    public class Bar  {
      public static final SumClass barVar;
      static  {
         barVar = Foo.fooVar;  // <<<--- set to null !
    }Warning: Speculation ahead.
    Normally the initial reference to Foo would cause Foo's class object to instantiate, initializing Foo's static variables, then running static{}. But apparently a static initializer cannot be triggered from within another static initializer. Can anyone confirm?
    How to fix/avoid: Obviously, one could avoid use of the static initializer. The illustration doesn't call for it.
    public class Foo  {
      public static final SumClass fooVar = new SumClass();  // either this ..
    public class Bar  {
      public static final SumClass barVar = Foo.fooVar;  // .. or this would prevent the problem
    }But there are times when you need to use it.
    So what's an elegant way to avoid the problem?

    DMF. wrote:
    jschell wrote:
    But there are times when you need to use it. I seriously doubt that.
    I would suppose that if one did "need" to use it it would only be once in ones entire professional career.Try an initializer that requires several statements. Josh Bloch illustrates one in an early chapter of Effective Java, IIRC.
    Another classic usage is for Singletons. You can make one look like a Monostate and avoid the annoying instance() invocation. Sure, it's not the only way, but it's a good one.
    What? You only encounter those once in a career? We must have very different careers. ;)
    So what's an elegant way to avoid the problem? Redesign. Not because it is elegant but rather to correct the error in the design.<pff> You have no idea what my design looks like; I just drew you a couple of stick figures.If it's dependent on such things as when a static initializer runs, it's poor. That's avoidable. Mentioning a case where such a dependency is used, that's irrelevant. It can be avoided. I know this is the point where you come up with a series of unfortunate coincidences that somehow dictate that you must use such a thing, but the very fact that you're pondering the problem with the design is a design problem. By definition.
    Besides, since what I was supposing to be a problem wasn't a problem, your "solution" isn't a solution. Is it?Well, you did ask the exact question "So what's an elegant way to avoid the problem?". If you didn't want it answered, you should have said so. I'm wondering if there could be any answer to that question that wouldn't cause you to respond in such a snippy manner. Your design is supposedly problematic, as evidenced by your question. I fail to see why the answer "re-design" is unacceptable. Maybe "change the way the Java runtime initializes classes" would have been better?
    This thread is bizarre. Why ask a question to which the only sane answer, you have already ruled out?

  • Value of x , static variable..

    In the method callMe() i am returning x , which is 0, that gets assigned to x in main(the same static variable), then i am incrementing x. But the value of x is 0.
    Whats happening.
    public class TestClass {
         static int x=0;
         static int callMe(){
              return x++;
         public static void main(String[] args) {
              x = callMe();
              System.out.print("x= "+ x);
    }

    In the method callMe() i am returning x , which is 0,
    that gets assigned to x in main(the same static
    variable), then i am incrementing x. But the value of
    x is 0.
    Whats happening.
    public class TestClass {
         static int x=0;
         static int callMe(){
              return x++;
         public static void main(String[] args) {
              x = callMe();
              System.out.print("x= "+ x);
    syntax subtletly... i++ and ++i both do the same thing : increment 'i', but...
    i++ // value : i BEFORE incrementation
    ++i // value : i AFTER incrementationabundantly documented and answered on this forum, next time, use the search button ;-)
    hth

  • Urgent!!! How to give a value to a BEx variable in the planning fuction?

    Hi all,
    does anybody know how can set variable's value in the palnning fuction (type exit) in IP?
    The two function modules in BPS which make this job don't work in the IP.
    thanks very much for any proposal.
    hongwei

    Hi,
    Reg the first part of the question, can you please explain how do you want to capture the variable for the custom planning function? Because, when I look at standard functions delivered by SAP, in the FROM CHANGE and TO CHANGE(for example copy function), we can select the BI variables or create new variables also.
    To pass the values to this variable from BEx Analyzer, we need to use the command range in BEx Analyzer and capture the values.
    I have used this approach to capture the BEx variable values into a FOX function using VARV function, but Im not pretty sure how to pass it to a custom planning function.
    Regarding the second part of the question can you pls look at FM :   RSPLSSE_PLSEQ_EXECUTE. I think you need to embedd your planning function into a sequence and call it with the above FM.
    You can also have a look at the ABAP program that is used to trigger a planning sequence by placing a breakpoint in any of the planning functions : "RSPLS_PLSEQ_EXECUTE" wherein you can pass the sequence name in the variant.
    Rgds
    Shyam

  • How to load a class , which isn't in the classpath environment variable.

    Hi, you folks.
    I have one problem. I want to load a class, which isn't in the classpath
    environment variable and I don't want to put into classpath. which method
    JVM can use to load it?
    Waitting for your sage advice.
    Regareds
    Hunter.Xiao

    You will have to write your own ClassLoader, or use something like URLClassLoader (I've never used this myself, but I've seen it mentioned elsewhere in this forum). Look here.

  • How to exclude values in an exit variable?

    Hello experts,
    I try to exclude special values from my selection via exit variable but I get an error of invalid values.
    could it be that something in my selection table is wrong? Do I have to use an other value for SIGN or OPT to exclude values?
    my Coding is:
    l_s_range-low  = '0000000404'.
    l_s_range-sign = 'E'.
    l_s_range-opt  = 'EQ'.
    APPEND l_s_range TO e_t_range.
    I tested my values with include them (SIGN = I) and this works fine.
    settings of the variable are:
    Type of variable:      characteristc value
    processing by:         Customer exit
    variable represents: Multiple single values.
    Where is the Error?
    Thanks in advance
    Johannes

    Hi there,
    I tried once to do that, i.e., with customer defined variable use the exclude sign 'E' for a variable but it doesn't work.
    Don't know why, but excluding values with 'E' doesn't work.
    Although it seems stupid you might consider excluding that value directly in the query in filter, or use BT from a value till 0000000403 and other BT from 0000000405 to above.
    Diogo.

  • How to Derive value in a text variable from numeric variable.

    Hello experts!!
    I have a requirement where i need to show some derived text in the column headers of my BEx query.
    Say i have a text variable for the column header FYT which need to have the fiscal year text. I have another variable on 0FISCYEAR -- FY which has values of the fiscal year.
    I have used FYT = &FY&, so, if FY = 2007, then the column header will show '2007'.
    But my requirement is, If FY = 2007, then FYT should have FY-1, if FY = 2008, FYT should have FY-2 and so on.
    I am not sure if we can use a normal and a text variable in a formula together. Please suggest what to do.
    Thanks and Best Regards,
    Vikas Bittera.

    Hi Bob,
    Thanks for the reply. But i am very clear about the explanation given. I enter one FY value on the screen say 2007.
    Now depending on this value i have multiple columns say for 2008, 2009, 2010. So it will always vary according to the entered year. For example if i enter 2006, then i will have columns for 2007, 2008 and 2009.
    The requirement is to show text for these columns. Say FY-1, FY-2 and FY-3. But this text is not same always. Say i take the year 2007 as my reference year for the start of use of my application.
    Then when i will put 2008, then my columns should display FY-2, FY-3 and FY-4.
    Please give the steps needed for the same. Be assured for full points
    Thanks and Best Regards,
    Vikas Bittera.

  • Loading values... getting displayed in the dropdown

    Hi All,
    1) Loading values... is getting displayed in the dropdown in the new checkin form as well as the update form.
    I have tried several options to resolve this like restarting the VM, publishing the schema again without any success.
    There is no error seen in the logs.
    Kindly suggest what else can be done?
    2) I have created a custom filter component and written an RIDC code for it that performs some validation on the metadata. How can I display the error message as a pop-up on the content server during checkin in case the validation fails.
    Thanks

    2. Throw a ServiceException.
    Jonathan
    http://jonathanhult.com

Maybe you are looking for

  • Could not complete your request because of a program error after text layers prompt

    For the past 4 months I have been receiving a message saying "Some text layers might need ot be updated before they can be used for vector based output.  Do you want to update these layers now?"  In the past I simply click update and go on with my bu

  • Connect to LCD HDTV

    Hey all I have a mini-dvi - dvi, dvi - HDMI with my MacBook. I got it connected, but it wouldn't show my whole screen. I went into system preferences and started changing some options and then my TV screen just went blank, saying that I needed to che

  • My iPhoneis disabled and says to connect to iTunes.  How can I get the phone unlocked?

    My daughter tried to change her code to unlock her phone and the phone locked up and says that her phone is diabled and to connect to iTunes.  Is there any thing to do to unlock fix this problem?

  • IWeb 08 and Podcast Maker

    I've recently started making podcasts for a radio station I help out on. Intially what I have done is used Garage Band and iWeb to create a podcast page/feed on my mobile me site. However on submitting this to itunes I could not get the main podcast

  • Texting Verizon's Roadside Service

    Why is it I can text the whole world but I can't text Verizon's road side service I lost my voice in 2008 due to cancer of the larynx so I am mute last time I had a break down I had to have a stranger call for me Why can't Verizon offer texting for t