• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

properties values not being set

 
dale con
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
dale con
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's alright managed to sort this out



Thanks for your help !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic