I am trying to connect to a database with phpMyadmin but I get an nullpointer in properties
Here is my code:
public Connection getConnection() throws SQLException {
final String ip = prop.getProperty("database_ip");
final String dir = prop.getProperty("database_dir");
final String username = prop.getProperty("database_username");
final String password = prop.getProperty("database_password");
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
throw new IllegalStateException("No suitable driver found");
}
return DriverManager.getConnection("jdbc:mysql://" + ip + "/" + dir, username, password);
}
and here is where the nullpointer happens:
private Properties getPropertyFile(String path) {
Properties prop = new Properties();
try {
prop.load(getClass().getClassLoader().getResourceAsStream(path));
} catch (IOException e) {
e.printStackTrace();
}
return prop;
}