• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

strange problem...

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ");
}
}
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chuan,


I do not understand the reason it is not work


My guess is that this line of your code

is not doing what you expect it to do.
Have you verified the result of this line of your code?
Good Luck,
Avi.
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic