File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to set database file's name into a singleton Data class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to set database file Watch "How to set database file New topic
Author

How to set database file's name into a singleton Data class.

Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
Hi all.
My Data class is a singleton, there is a private constructor with one parameter and getInstance() method as following code:



In Sun's instructions, a user can put a database file's name via a GUI. When my application gets the database name, how can I push it into Data class, because my constructor can not be invoked direcly.

Thank you.
Surasak Lee
S Perreault
Ranch Hand

Joined: Oct 29, 2003
Posts: 37
An idea would be to always read the properties from the suncertify.properties file for your Data class to find the database.

UI updates the properties file and then the data class is constructed from the properties file.

I don't know if this will help you but it's an idea =)

Perogi.
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
Please anyone help me.

Surasak Lee
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11490
    
  95

Hi Surasak,

Perogi gave a good solution. Instead of just asking for more help, perhaps you could say what you see as being wrong with the solution given?

Alternative: have a setter method which sets the database name. Any attempts to get the instance of your Data class before the name is set will fail (with a suitable exception).

Another alternative: have the filename passed in as a parameter of the get instance method. That will have the added benefit of making it easy to change your Data class to a Multiton (instead of a Singleton) later.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
Don't get me started about those stupid light bulbs.
 
subject: How to set database file's name into a singleton Data class.