Note that there are some explanatory texts on larger screens.

plurals
  1. POStatic reference to three objects, but no matter which object I return, the same value is returned
    text
    copied!<p>I have a static GlobalVariables class that holds three different database instances in it.</p> <pre><code>private static GlobalVarsDatabase dBOne = null; private static GlobalVarsDatabase dBTwo = null; private static GlobalVarsDatabase dBThree = null; public class GlobalVars { public static GlobalVarsDatabase getdBOne() { return dBOne; } public static void setdBOne(GlobalVarsDatabase dBOne) { GlobalVars.dBOne= dBOne; }} </code></pre> <p>etc, etc </p> <p>I then read in data from an XML file using DOM and create three objects to save to. </p> <p>(I have already checked the values within these objects through debug mode and they are correctly read) </p> <p>Then I set each of the databases with the instance I create;</p> <pre><code>GlobalVariables.setDBOne(dbOne); </code></pre> <p>etc etc </p> <p>My GlobalVarsDatabase class only contains getters and setters defined as such;</p> <pre><code>public static String getMinConnections() { return minConnections; } public static void setMinConnections(int minConnections) { GlobalVarsDatabase.minConnections= minConnections; } </code></pre> <p>I assign variables to the setters through DOM parsing by;</p> <p>creating a database object;</p> <pre><code> GlobalVarsDatabase dBOne= new GlobalVarsDatabase(); </code></pre> <p>Then I use this object to set the min connections;</p> <pre><code> dBOne.setMinConnectionsPerPartition(Integer.parseInt(dbPoolElement.getElementsByTagName("ConPoolminConnections").item(0).getTextContent())); </code></pre> <p>And pass this object through to GlobalVars:</p> <pre><code>GlobalVariables.setDbOne(dBOne); </code></pre> <p>but when I come to reference any of the specific values I want, it will constantly give me the same information, </p> <p>So:</p> <pre><code>GlobalVariables.getDbOne().getMinConnections(); GlobalVariables.getDbTwo().getMinConnections(); GlobalVariables.getDbThree().getMinConnections(); </code></pre> <p>All retrieve the same information, even though different information has been saved to each individual object. </p> <p>I though a static class could be referenced by any other class with the same information available but is there any ideas of where this may be possibly going wrong ?</p> <p>Thank you for the feedback to improve my question, really helpful :) </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload