java - Reading Config File Contents -


i trying read "db_config_file.properties" file reason following error occurring:

exception in thread "awt-eventqueue-0" java.lang.nullpointerexception     @ java.lang.class.forname0(native method)     @ java.lang.class.forname(class.java:186) 

my class handling reading of config file looks following:

public class database {

public static connection conn; public static void dbconnection() throws filenotfoundexception, ioexception, classnotfoundexception, sqlexception {          properties props = new properties();         driver = props.getproperty("driver");         string url = props.getproperty("url");         string username = props.getproperty("username");          string password = props.getproperty("password");         string configfile = "f:/project/java project/src/mainscreen/db_config_file.properties";          inputstream ins = new fileinputstream(configfile);          props.load(ins);         class.forname(driver);           conn = drivermanager.getconnection(url, username, password); 

}

judging error guessing there wrong in "class.forname(driver)" part.

can please me out here?

thanks

you loading properties file input stream after reading values it. variable 'driver' null properties empty , causing npe.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -