IS there static variables in oracle 9i??

Hi,
I have a requirement.
I am establishing an orcale 9i connection from my .net application.
Now I am calling an SP and it has a global count variable initialized to 0, and It fetches a count of * from one table and also there are other functionality that the SP does.
Now I want to persisit this count variable's value , so that next time the SP is called ( in the same connection), I will make a check that if the count variable is not 0 then dont execute the query to populate the count variable.
Normally in java, .net etc... we can create static variables for this purpose.
Can the same be done in PL/SQL?
If not what would be the alternative?
Thanks folks.
s

Hi,
Please have a look.
SQL> create or replace package test_pkg
2 is
3 procedure test_1;
4 end test_pkg;
5 /
Package created.
SQL> create or replace package body test_pkg
2 as
3 global_cnt number(10):=0;
4 procedure test_1
5 is
6 begin
7 if global_cnt > 0
8 then
9 dbms_output.put_line('No RUN');
10 else
11 dbms_output.put_line('RUN');
12 global_cnt := global_cnt + 1;
13 end if;
14 end;
15 end test_pkg;
16 /
Package body created.
SQL> set serveroutput on
SQL> exec test_pkg.test_1
RUN
PL/SQL procedure successfully completed.
SQL> exec test_pkg.test_1
No RUN
PL/SQL procedure successfully completed.
SQL> exec test_pkg.test_1
No RUN
PL/SQL procedure successfully completed.
SQL>
-----------------------------------------------------------------------

Similar Messages

  • Shared java static variables

    I have an application where I would like to
    read from some small configuration tables
    and cache them into java variables, in order to avoid each stored procedure call to redo
    those queries. The configuration data is
    pretty static, so I don't worry about refresh
    problems.
    My first attempt to do that was using static
    final variables (like Vector). In our oracle
    environment however (8.1.7) each session
    seems to have its own copy of static final
    variables, resulting in each session to
    perform those queries for initializing all
    over again.
    firstly, i would like to find out if there is another way to share this data among java
    sessions, but otherwise I am curious how
    I can get the claims made in http://technet.oracle.com/products/oracle8i/pdf/8ir2java.pdf , page 6 to work.
    Specifically, here is what the document says:
    "In Oracel8i Release 2, JServer introduces the concept of "hotloaded" classes. Various core classes that
    initialize static variables known to be constant are pre-initialized during database creation time. When you use
    one of these classes in your program, the class loader loads the pre-initialized form. In many cases, the time
    required to initialize the static variables is itself quite significant, and now with the introduction of hotloaded
    classes that time is completely eliminated. In addition, the objects in these particular static variables are shared
    among all sessions. Hotloaded classes therefore improve performance by eliminating class initialization and
    they reduce per-user-session footprint by increasing the amount of data shared between sessions. Hotloaded
    classes provide improved performance and scalability "for free", with no user intervention. "
    the kind of initialization I have been
    trying is like:
    public static final int inti = func();
    this also didn't seem to work:
    public static final int inti;
    static {
    inti = ....;
    thanks,
    null

    I have an application where I would like to
    read from some small configuration tables
    and cache them into java variables, in order to avoid each stored procedure call to redo
    those queries. The configuration data is
    pretty static, so I don't worry about refresh
    problems.
    My first attempt to do that was using static
    final variables (like Vector). In our oracle
    environment however (8.1.7) each session
    seems to have its own copy of static final
    variables, resulting in each session to
    perform those queries for initializing all
    over again.
    firstly, i would like to find out if there is another way to share this data among java
    sessions, but otherwise I am curious how
    I can get the claims made in http://technet.oracle.com/products/oracle8i/pdf/8ir2java.pdf , page 6 to work.
    Specifically, here is what the document says:
    "In Oracel8i Release 2, JServer introduces the concept of "hotloaded" classes. Various core classes that
    initialize static variables known to be constant are pre-initialized during database creation time. When you use
    one of these classes in your program, the class loader loads the pre-initialized form. In many cases, the time
    required to initialize the static variables is itself quite significant, and now with the introduction of hotloaded
    classes that time is completely eliminated. In addition, the objects in these particular static variables are shared
    among all sessions. Hotloaded classes therefore improve performance by eliminating class initialization and
    they reduce per-user-session footprint by increasing the amount of data shared between sessions. Hotloaded
    classes provide improved performance and scalability "for free", with no user intervention. "
    the kind of initialization I have been
    trying is like:
    public static final int inti = func();
    this also didn't seem to work:
    public static final int inti;
    static {
    inti = ....;
    thanks,
    null

  • Global static variable. I just CANNOT get global for everything

    Hi,
    I copied a connection pool example from oracle web site. It uses static variable. Its not a servlet, its a javabean. I can run a million times in one session and everything is great. If I open up another session, it creates another instance and creates more connections when it should be seeing the previous instance.
    My question is how to make a static variable global to the entire application? Do i have to initialize it in the servlet container? All im doing is calling a JSP page which calls this bean. If instance is null, create 5 new connections. Well like i stated above, it works for a single session. It appears that each session gets its own instance. I have been working and debugging this for a long time and I just cannot come up with a solution...
    Any ideas???
    Thanks as always

    Declar it as static within the servlet class.
    public class MyServlet extends HttpServlet {
    public static ConnectionPool pool;
    Then you can access it from any JSP/Servlet using MyServlet.pool but you may have to import the class into the JSP/Servlet.
    Be aware that there may be synchroniztion issues when you access this static object so you may want to synchronize access to the pool.
      synchronized (application) {
           if (MyServlet.pool == null) { //initialize pool code here }

  • Is there a way in Oracle to return multiple rows as a single string?

    Hi gurus,
    I just got help from your guys fixing my dynamic sql problem. What I am doing in that function is to return a single string from multiple rows and I use it in the select statement. It works fine once the problem was solved. But is there any way in Oracle to do this in the select statement only? I have a table that stores incidents (incident_id is the PK) and another table that stores the people that are involved in an incident.
    Incident_table
    (incident_id number PK);
    Incident_people_table
    (incident_id number PK/FK,
    person_id number PK);
    Now in a report, I need to return the multiple rows of the Incident_People_table as a single string separated by a comma, for example, 'Ben, John, Mark'. I asked the SQL Server DBA about this and he told me he can do that in SQL Server by using a variable in the sql statement and SQL Server will auomatically iterate the rows and concatenate the result (I have not seen his actual work). Is there a similar way in Oracle? I have seen some examples here for some similar requests using the sys_connect_by_path, but I wonder if it is feasible in a report sql that is already rather complex. Or should I just stick to my simpler funcion?
    Thanks.
    Ben

    Hi,
    May be, this example will help you.
    SQL> CREATE TABLE Incident_Table(
      2    incident_id number
      3  );
    Table created.
    SQL> CREATE TABLE Person_Table(
      2    person_id number,
      3    person_name VARCHAR2(200)
      4  );
    Table created.
    SQL> CREATE TABLE Incident_People_Table(
      2    incident_id number,
      3    person_id number
      4  );
    Table created.
    SQL> SELECT * FROM Incident_Table;
    INCIDENT_ID
              1
              2
    SQL> SELECT * FROM Person_Table;
    PERSON_ID PERSON_NAME
             1 John
             2 Mark
             3 Ben
             4 Sam
    SQL> SELECT * FROM Incident_People_Table;
    INCIDENT_ID  PERSON_ID
              1          1
              1          2
              1          3
              2          1
              2          2
              2          4
    6 rows selected.
    SQL> SELECT IT.*,
      2    (
      3      WITH People_Order AS (
      4        SELECT IPT.incident_id, person_id, PT.person_name,
      5          ROW_NUMBER() OVER (PARTITION BY IPT.incident_id ORDER BY PT.person_name) AS Order_Num,
      6          COUNT(*) OVER (PARTITION BY IPT.incident_id) AS incident_people_cnt
      7        FROM Incident_People_Table IPT
      8          JOIN Person_Table PT USING(person_id)
      9      )
    10      SELECT SUBSTR(SYS_CONNECT_BY_PATH(PO.person_name, ', '), 3) AS incident_people_list
    11      FROM (SELECT * FROM People_Order PO WHERE PO.incident_id = IT.incident_id) PO
    12      WHERE PO.incident_people_cnt = LEVEL
    13      START WITH PO.Order_Num = 1
    14      CONNECT BY PRIOR PO.Order_Num = PO.Order_Num - 1
    15    ) AS incident_people_list
    16  FROM Incident_Table IT
    17  ;
    INCIDENT_ID INCIDENT_PEOPLE_LIST
              1 Ben, John, Mark
              2 John, Mark, SamRegards,
    Dima

  • Error on compile - non-static variable can not be referencedfrom static con

    Error on compile happening with addButton?
    Thanks
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.JFrame;
    public class Log implements ActionListener {
    JButton addButton;
    public static void addComponentsToPane(Container pane) {
    pane.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
         c.gridy = 3;
    c.gridx = 0;
         JLabel callsignLabel= new JLabel("Callsign");
    pane.add(callsignLabel, c);
         c.gridy = 3;
    c.gridx = 1;
         JLabel nameLabel= new JLabel("Name");
    pane.add(nameLabel, c);
         c.gridy = 3;
    c.gridx = 2;
         JLabel timeLabel= new JLabel("Time");
    pane.add(timeLabel, c);
         c.gridy = 3;
    c.gridx = 3;
         JLabel dateLabel= new JLabel("Date");
    pane.add(dateLabel, c);
         c.gridy = 3;
    c.gridx = 4;
         JLabel frequencyLabel= new JLabel("Freq ");
    pane.add(frequencyLabel, c);
         c.gridy = 3;
    c.gridx = 5;
         JLabel locationLabel = new JLabel("Country/State");
    pane.add(locationLabel, c);
    c.gridy = 5;
    c.gridx = 0;
         addButton = new JButton("Add");
    pane.add(addButton, c);
         addButton.addActionListener(this);

    Thank you for the reply
    I am new to Java
    What is wrong with the way it is coded?The error message tells you what's wrong: You're trying to reference a non-static variable from a static context.
    If you don't know what that means, then click the link I provided and look at the results from that google search. You might have to go through a few before you find a satisfactory explanation. And after you've done that, if you have specific questions about things you didn't understand there, please post again.

  • How can I write an instance of a class in a static variable

    Hi !
    I have an instance of a class
    Devisen dev = new Devisen();
    In an other class I have a static method and I need there the content of some variables from dev.
    public static void abc()
    { String text=dev.textfield.getText()
    I get the errormessage, that the I cannot use the Not-static variable dev in a static variable.
    I understand that I cannot reference to the class Devisen because Devisen is not static I so I had to reference to an instance. But an instance is the same as a class with static methodes. (I think so)
    Is there a possibility, if I am in a static method, to call the content of a JTextField of an instance of a class ?
    Thank you Wolfgang

    Hallo, here is more code for my problem:
    class Login {
       Devisen dev=new Devisen();
    class Devisen {
       JTextField field2;
       if (!Check.check_field2()) return; // if value not okay than return
    class Check {
       public static void check_field2()
         HOW TO GET THE CONTENT OF field2 HERE ?
    One solution ist to give the instance to the static function, with the keyword "this"
    if (!Check.check_field2(this)) return;and get the instance
    public static void check_field2(Devisen dev)BUT is that a problem for memory to give every method an instance of the class ? I have 50 fields to control and I dont want do give every check_method an instance of Devisen, if this is a problem for performance.
    Or do I only give the place where the existing instance is.
    Hmm...?
    Thank you Wolfgang

  • Using Static Variable against Context Attribute for Holding IWDView

    Dear Friends,
    I have a method which is in another DC which has a parameter of the type IWDView. In my view, I will have an action which will call the method in another component by passing the value for the view parameter. Here, I can achieve this in 2 types. One is - I declare a static variable and assign the wdDoModifyView's view as parameter value and I can pass this variable as parameter whenever calling that method or the second way - create an attribute and assign the same wdDoModifyView's view parameter as its value. Whenever I call this method, I can pass this attribute as parameter. What is the difference between these two types of holding the value since I am storing the same value i.e., wdDoModifyView's view parameter. But when I trigger the action from different user sessions, the first type of code (using static variable) prints the same value in both the sessions for view.hashCode() and View.toString(), but the same is printing the different values when I pass the attribute which holds the view parameter.
    Clarification on this is highly appreciated
    The problem I face is when I use static variable to get the view instance and export the data using the UI element's id, the data belonging to different user sessions is mixed up where as when I use Context Attribute, the same problem doesn't arise. I want to know the reason why it is so. Is there any other place or way where I can get the current view instance of each session instead of wdDoModifyView?

    Hi Sujai ,
    As you have specified the problem that we face when we use  static attributes, when end users are using the application .
    Static means i  have n number of objects but the static variable value will remain same every where.
    when it is context attribute for every object i.e nth object you have a nth context attribute i mean nth copy of the context attribute.
    so every user has a unique Iview parameter , when context is used and
    when static is used  , assume you have userA , his iview is set this intially  and u have another user B , when he is using  , since the variable is static and when you access this variable you will get the value of userA.
    Regards
    Govardan Raj

  • 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.

  • Non-static variable cant accessed from the static context..your suggestion

    Once again stuck in my own thinking, As per my knowledge there is a general error in java.
    i.e. 'Non-static variable cant accessed from static context....'
    Now the thing is that, When we are declaring any variables(non-static) and trying to access it within the same method, Its working perfectly fine.
    i.e.
    public class trial{
    ���������� public static void main(String ar[]){      ////static context
    ������������ int counter=0; ///Non static variable
    ������������ for(;counter<10;) {
    �������������� counter++;
    �������������� System.out.println("Value of counter = " + counter) ; ///working fine
    �������������� }
    ���������� }
    Now the question is that if we are trying to declare a variable out-side the method (Non-static) , Then we defenately face the error' Non-static varialble can't accessed from the static context', BUT here within the static context we declared the non-static variable and accessed it perfectly.
    Please give your valuable suggestions.
    Thanks,
    Jeff

    Once again stuck in my own thinking, As per my
    knowledge there is a general error in java.
    i.e. 'Non-static variable cant accessed from static
    context....'
    Now the thing is that, When we are declaring any
    variables(non-static) and trying to access it within
    the same method, Its working perfectly fine.
    i.e.
    public class trial{
    ���������� public static void
    main(String ar[]){      ////static context
    ������������ int counter=0; ///Non
    static variable
    ������������ for(;counter<10;) {
    �������������� counter++;
    ��������������
    System.out.println("Value
    of counter = " + counter) ; ///working fine
    �������������� }
    ���������� }
    w the question is that if we are trying to declare a
    variable out-side the method (Non-static) , Then we
    defenately face the error' Non-static varialble can't
    accessed from the static context', BUT here within
    the static context we declared the non-static
    variable and accessed it perfectly.
    Please give your valuable suggestions.
    Thanks,
    JeffHi,
    You are declaring a variable inside a static method,
    that means you are opening a static scope... i.e. static block internally...
    whatever the variable you declare inside a static block... will be static by default, even if you didn't add static while declaring...
    But if you put ... it will be considered as redundant by compiler.
    More over, static context does not get "this" pointer...
    that's the reason we refer to any non-static variables declared outside of any methods... by creating an object... this gives "this" pointer to static method controller.

  • Non static variable error

    There may be more errors in here besides the static variable error. I made the methods static for the method call in my constructor Product(name, price). The purpose of this Class is to the the name and price of a product from user input, subtract 5.00 from the price, and return the new price. Please help!!!
    public class Product
    public Product(String name, double price)
    String product;
    price = Product.getPrice(price);
    Double.toString(price);
    //this.product = product;
    product = Product.getName(name) + Product.getPrice(price);
    public static String getName(String name)
    System.out.println("What is their name?: ");
    name = in.nextLine(); // I GET A NONSTATIC VARIABLE ERROR FOR variable "in" HERE.
    return name;
    public static double getPrice(double price)
    this.price = price;
    System.out.println("What is the price?: ");
    price = in.nextDouble();
    return price;
    public double reducePrice()
    price = price - 5.00;
    return price;
    public String getProduct()
    product = new Product(name, price);
    return product;
    Scanner in = new Scanner(System.in);
    public static String name;
    //public double price;
    }

    you not define the class member properly.
    the class member is define before the constructor as
    public class Product {
         static Scanner in = new Scanner(System.in);
         String product;
         double price;
         public static String name;
         public Product(String name, double price) {
              price = Product.getPrice(price);
              Double.toString(price);
              // this.product = product;
              product = Product.getName(name) + Product.getPrice(price);
    }

  • "non-static variable cannot be referenced from a static contex"

    Hi, i'm writing a booking program at school and i'm getting 27 "non-static variable cannot be referenced from a static contex" errors. I can't find anything wrong with the code so I'm just asking you guys to look it through..
    public class bokningsmeny
    Bokning[] bokningslista = new Bokning[1000];
    String fornamn;
    String efternamn;
    String civilstand;
    String adress;
    String personnr;
    String telefonnr;
    int regnr;
    double inkomst;
    public static void main(String[] args)
    for(;;)
    System.out.println("\nMeny");
    System.out.println("________\n");
    System.out.println("1. Mata in nya personer.");
    System.out.println("2. S&ouml;k personen via personnummer och skriv personens andra uppgifter.");
    System.out.println("3. S&ouml;k personen via efternamn och skriv personens andra uppgifter.");
    System.out.println("4. S&ouml;k personen via personnummer och &auml;ndra adress.");
    System.out.println("5. S&ouml;k personen via personnummer och &auml;ndra telefonnummer.");
    System.out.println("6. S&ouml;k personen via personnummer och &auml;ndra civilst&aring;nd.");
    System.out.println("7. S&ouml;k personen vis personnummer och &auml;ndra inkomst");
    System.out.println("8. Skriv ut alla personer med givet namn.");
    System.out.println("9. Skriv ut alla personer med givet efternamn");
    System.out.println("10. Skriv ut alla personer med given adress");
    System.out.println("11. Skriv ut hela listan");
    System.out.println("12. Avsluta\n");
    int menyval = Keyboard.readInt();
    System.out.println("\n");
    switch(menyval)
    case 1:
    System.out.println("Mata in nya personer.\n______________________\n");
    boolean BOOuppgifter = false;
    for(int i = 0; i <= 1000; i++)
    if(bokningslista +== null)+
    +{+
    +SkrivInUppgifter();+
    +System.out.println("\nSt&auml;mmer informationen? (Y/N)");+
    +boolean BOOcase1yesorno = IsInputCorrect();+
    +if(BOOcase1yesorno == true)+
    +{+
    +System.out.println("\nBokningen lyckades!\n");+
    +bokningslista += new Bokning(fornamn, efternamn, civilstand, adress, personnr, telefonnr, regnr, inkomst);
    ++++else if(BOOcase1yesorno == false
    ++++System.out.println("\nBokningen avbruten.\n")
    ++++break
    ++++++break
    ++++case 2
    ++++System.out.println("Sok person med personnummer och &auml;ndra uppgifter.")
    ++System.out.println("___________________________________________________________\n")
    ++System.out.print("Skriv in sokord: ")
    ++String query = Keyboard.readString()
    ++query = query.toUpperCase()
    ++String personnummersok
    ++boolean contains
    ++int antal = 0
    ++boolean BOOcase2result = false
    ++System.out.println("Resultat: \n_________\n")
    ++for(int i = 0; i < 1000; i++
    ++++if(bokningslista +!<b<br />+<em<b<br />+++personnummersok = (bokningslista+.hamtaPersonnum()).t
    ++++contains = personnummersok.con
    ++++if(cont
    +<<br />++++BOOcase2r
    ++++ant
    ++++fornamn = bokningslist
    +++++efternamn = boknin
    ++++++personnr
    +++++++System.out.println(antal + ". " + fornam
    ++++<e<br />+++++++System.out.pri<br<br />+++++<em<br />+++++++System.out.println("\nVilket sokresultat vill du v&bdquo
    ++++<<br />+++++++if(case2ch
    +++++++System.ou
    +++<e<<br />+++<em<br />++++
    ++<em<br />+++++++System.out.p
    +++++<e<br />+++<<br<br /<br />+++++++System.out.printl
    +++<em<br />+++++<em<br />++
    <e<br />++++++++Sy
    +++++
    ++++++<e<br /><em<br />++++++++<<br />+++++<e<br />+++
    +++<<br />+++++++++else if(case11exit != 'y' &<br<br />+<<br />++++
    ++++
    +++++
    ++++<e<br />+++++++
    ++++<em<br />+++++
    +++<em<br />+++++<em<br />++++<<br />++++++
    ++++<e<br />+++++++<e<br />++<em<br />++++<e<br />+++<<br />+++++++++System.out.println("\n\nNamn: " + fornamn + "
    ++++++++++ "\nHemadress: " + adr
    ++++++++++ telefon
    +<<br />+++++++++Syste
    ++++<em<br />+++++++++if(correct
    <em<br />++<em<br />++<<br />++++<e<br /><<<br /><e<br />+++++++++I have another file with the Bokning.java class in it but I know for sure that its error free. Notice that I'm not nearly done with the program, theres like 10 more 'cases' to be created but I dont w
    ++<em</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Your code goes "+" crazy there, but here is your problem:
    public class B extends A {
        public void method() {}
        public static void main(String[] args) {
            //method(); //non-static method method() cannot be referenced from a static context
            B b = new B();
            b.method();
    }You need to be clear about the difference between static methods and non-static (instance) methods. Instance methods are applied to objects.

  • Non static variable errors

    I have been working on this file for 4 days now and I can't get past these errors.
    Here's the whole project:
    package toysmanager;
    public class ToysManager {
    //Method ToysManager
    public ToysManager() {
    //Method main
    public static void main(String[] args) {
    ToddlerToy Train1 = new ToddlerToy();
    ToddlerToy Train2 = new ToddlerToy();
    ToddlerToy Train3 = new ToddlerToy();
    System.out.print("This is an object of type ToysManager");
    Train1.PrintProductID();
    Train2.PrintProductID();
    Train3.PrintProductID();
    public class ToddlerToy{
    private int ProductID = 0;
    private String ProductName = "";
    private float ProductPrice = 0;
    public ToddlerToy(int id,String name, float price){
    ProductID = id;
    ProductName = name;
    ProductPrice = price;
    //Method PrintProductID
    public int PrintProductID(){
    System.out.print("This method is PrintProductID in the class ToddlerToy");
    System.out.print("Product ID is:" + ProductID);
    return ProductID;
    public String PrintProductName(){
    System.out.print("This method is PrintProductName in the class ToddlerToy");
    System.out.print("Product Name:" + ProductName);
    return ProductName;
    public float PrintProductPrice(){
    System.out.print("This method is PrintProductPrice in the class ToddlerToy");
    System.out.print("Product Price: $" + ProductPrice);
    return ProductPrice;
    And here are the errors:
    "ToysManager.java": non-static variable this cannot be referenced from a static context at line 9, column 29
    "ToysManager.java": ToddlerToy(int,java.lang.String,float) in toysmanager.ToysManager.ToddlerToy cannot be applied to () at line 9, column 29
    "ToysManager.java": non-static variable this cannot be referenced from a static context at line 10, column 29
    "ToysManager.java": ToddlerToy(int,java.lang.String,float) in toysmanager.ToysManager.ToddlerToy cannot be applied to () at line 10, column 29
    "ToysManager.java": non-static variable this cannot be referenced from a static context at line 11, column 29
    "ToysManager.java": ToddlerToy(int,java.lang.String,float) in toysmanager.ToysManager.ToddlerToy cannot be applied to () at line 11, column 29
    Any help would be appreciated as I am plainly not understanding this even with a book.

    Annie:
    Could you help me understand the original ToyManager instructions more please? Not asking you to do the work for me I just do not understand exactly what they want me to do...
    Assignment:
    After you install JCreator, write a Java program, with a single class called ToysManager. The main method should print the name of the class, for example: "This is an object of type ToysManager."
    (Hint: the process is very similar to the "Hello World!" program.)
    Please add file (.java)
    Group Portion:
    Deliverables:  two *.java files
    As a group, add a second class called ToddlerToy to your ToysManager project.
    Here are  the requirements for the ToddlerToy:
        * The class ToddlerToy is public and has a default constructor.
        * It  has  one private attribute called  ProductID (of type int).
        * It has two public  methods called  SetProductId() and PrintProductId().
        * The method SetProductId() assigns a value to the attribute ProductId. For now, the value is hard-coded.
        * The method  PrintProductId prints the value of the attribute ProductId.
        * The class ToddlerToy has no main() method.  In Java, there is only one main method for the entire program. In this case, the main method is in the ToysManager class.
    Here are the requirements for the main method of the ToysManager class:
        * Create an object called Train1 of  class  type ToddlerToy, using the default  constructor.
        * Call the methods SetProductId() and PrintProductId() to set then print the the value of ProductId.
        * The first statement  in each method should print the name of the method, for example:  "This is method <method name> in class <class name>". This should help you trace the execution of your program. Feel free to comment out the print statement.
        * On the Small Group Discussion Board, discuss your understanding of the concepts of class, object, constructor, method, and attribute.
        * Give one example of a class (giving its name, attributes, and methods)  that could be part of the shipping application.ANY help with this at all is greatly appreciated...a friend of mine found your post and used it to give me code snippets for help and I had no idea. Nearly got me in deep water...redoing the assignment but personally I find the next two assignments much easier to understand than this one. The instructions are confusing to me...can you point me in the right direction?

  • Non-static variable change cannot be referenced from a static context

    My compiler says: : non-static variable change cannot be referenced from a static context
    when i try to compile this. Why is it happening?
    public class change{
      int coin[] = {1,5,10,25,50};
      int change=0;
      public static void main(){
        int val = Integer.parseInt(JOptionPane.showInputDialog(null, "Type the amount: ", "Change", JOptionPane.QUESTION_MESSAGE));
        change = backtrack();
    }

    A static field or method is not associated with any instance of the class; rather it's associated with the class itself.
    When you declared the field to be non-static (by not including the "static" keyword; non-static methods and fields are much more common so it's the default), that meant that the field was a property of an object. But the static main method, being static, didn't have an object associated with it. So there was no "change" property to refer to.
    An alternative way to get this work, would be to make your main method instantiate an object of the class "change", and put the functionality in other instance methods.
    By the way, class names are supposed to start with upper-case letters. That's the convention.

  • Java static variables in Stored Java

    I'm wondering if someone in Oracle could relate their thinking with regards to static variables in stored java and why were these implemented as they were. The aspect I'm referring to specifically is how these are basically working as PLSQL package variables, i.e. with state maintained for the life of the session.
    Outside the database, in the "normal" Java world, statics will only live as long as the program is running. But in the Oracle DB world, the static continues to live as long as the session. With this in mind, doesn't this difference compromise the idea of just inserting working Java code into the Database? i.e. static variables now have to be initialized every time a method is called, and cannot be assumed to have default values. Does that not seem like a rather large departure from what a non-DB java programmer would be doing?
    Thanks in advance for your thoughts on this.
    Joe Tseng

    It should generally be the case that all calls in a session see the same static variable values. Some actions will terminate the java session (and lose the static variable state) without ending the RDBMS session, such as calling System.exit from java, but normally this can't happen within a single RDBMS call. Perhaps if you give more details on how you are making the call from java to PLSQL one could say more. In particular, if the call happens to be via the JDBC thin driver then the session running in the JDBC connection will be distinct from the calling session.

  • Can we define 'Static Variables' in BPEL process ?

    Is the idea of 'STATIC VARIABLES' supported in Oracle BPEL?
    What I mean by that is, I need all my in-flight BPEL process INSTANCES to read a common variable and then decide the next course of action.
    Is this possible?
    Thanks in advance,
    Mahendra

    Hi Hans,
    In Cocoa and Objective-C a static variable needs to be declared in the implementation file and not the header as you would normally do. Standard C variables can be set at the same time as the declaration but Cocoa objects need an extra step.
    For example:
    #import "TestObject.h"
    // declare your static variable here
    static NSArray *count;
    @implementation TestObject
    - (id) init {
    self = [super init];
    if (self != nil) {
    // set the variable here
    // the 'if' statement ensures it is only set once
    if (!count) {
    count = [[NSArray arrayWithObjects:@"One",@"Two",@"Three",Nil] retain];
    return self;
    @end
    Hope this helps,
    Martin.
    PowerMac G5 1.6Ghz   Mac OS X (10.4.9)   4 gig RAM & NVidia 6800 Ultra

Maybe you are looking for