Fixed the problem with the following code - not the most gracious way - but i need a quick solution for this assignment
package six.desktop.gui.common;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
public class Config
{
private static final String configFileName = "/config/config.ini";
private Config()
{
}
public static String getPropertyValue(String propertyName) throws IOException
{
URL url = new Config().getClass().getResource(configFileName);
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String inputline = "";
while ((inputline = br.readLine()) != null)
{
if (inputline.contains(propertyName))
{
int index = inputline.indexOf(propertyName);
index += propertyName.length() + 1;
return inputline.substring(index, inputline.length());
}
}
return null;
}
}
I want to be able to config file which includes the database connection string that is to be located at the same level as the jar. How could i achieve this? or is there a different approach to what i want?
I have a DB handler class which at the moment has the connection just hardcoded in.