This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I have the following code which I do not understand the reason it is not work. i.e. Putting the driver, dbURL, login, password value in the beginning work, however, setting it in the try blocks does not. Can you please help me? Thank you. public ConnectionManager() { // (This block works OK if uncommented) //driver = "com.mysql.jdbc.Driver"; //dbURL = "jdbc:mysql://localhost/BOOKINGSYSTEM"; //login = "root"; //password = "password"; try { Properties Prop = new Properties(); InputStream configStream = ConnectionManager.class.getClass().getResourceAsStream("/config/database.properties"); Prop.load(configStream); configStream.close(); //driver =Prop.getProperty("driver"); //dbURL = Prop.getProperty("dbURL"); //login = Prop.getProperty("login"); //password = Prop.getProperty("password"); // (This block DOES NOT works...why??) driver = "com.mysql.jdbc.Driver"; dbURL = "jdbc:mysql://localhost/BOOKINGSYSTEM"; login = "root"; password = "password"; } catch(IOException e) { System.out.println("Error: Cannot laod configuration file "); } }
is not doing what you expect it to do. Have you verified the result of this line of your code? Good Luck, Avi.
Malli Raman
Ranch Hand
Joined: Nov 07, 2001
Posts: 312
posted
0
Originally posted by Chuan Ren: I have the following code which I do not understand the reason it is not work. i.e. Putting the driver, dbURL, login, password value in the beginning work, however, setting it in the try blocks does not. Can you please help me? Thank you. public ConnectionManager() { // (This block works OK if uncommented) //driver = "com.mysql.jdbc.Driver"; //dbURL = "jdbc:mysql://localhost/BOOKINGSYSTEM"; //login = "root"; //password = "password"; try { Properties Prop = new Properties(); InputStream configStream = ConnectionManager.class.getClass().getResourceAsStream("/config/database.properties"); Prop.load(configStream); configStream.close(); //driver =Prop.getProperty("driver"); //dbURL = Prop.getProperty("dbURL"); //login = Prop.getProperty("login"); //password = Prop.getProperty("password"); // (This block DOES NOT works...why??) driver = "com.mysql.jdbc.Driver"; dbURL = "jdbc:mysql://localhost/BOOKINGSYSTEM"; login = "root"; password = "password"; } catch(IOException e) { System.out.println("Error: Cannot laod configuration file "); } }
Hi, I am not sure about your problem. But why can't you call configStream.close(); at the end of the try loop. Regards, M.S.Raman