File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes properties values not being set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "properties values not being set" Watch "properties values not being set" New topic
Author

properties values not being set

dale con
Ranch Hand

Joined: Apr 15, 2005
Posts: 93
I have a method getPropertiesFile() that i want to call from another method

public static Connection getConnection() throws SQLException
{
getPropertiesFile();
}

Then i want open the properties file to read the vales so i have methods doing this e.g.

public static String getDbServer()
{
return properties.getProperty("DatabaseServer");
}

In my getConnection() i want to load the properties file and read the vales, so i've done this

public static Connection getConnection() throws SQLException
{
getPropertiesFile();
String dbServer = getDbServer();
....
}

But the values aren't being set even though i know the properties file is found

Can anyone tell me where i'm going wrong

many thanks



protected static Properties properties = new Properties();


public static void getPropertiesFile()
{
try
{
properties.load(myClass.class.getResourceAsStream("/myprops.properties"));
}
catch (IOException e)
{
System.out.println("Properties exception " + e.toString());
}
}
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Hi Gill,

Here is a link to the Java Coding Conventions. At some point I think it is a good idea to check it out, not that you have to do that now.

Also there are buttons under the Add Reply there are buttons to enhance your post. One of them is the CODE button which will create tags around your code to keep it formatted so that it is easier to read.

Why aren't you using the Properties class instead. This way you don't have to recreate the method for loading the properties file from scratch.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
dale con
Ranch Hand

Joined: Apr 15, 2005
Posts: 93
It's alright managed to sort this out



Thanks for your help !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: properties values not being set