aspose file tools*
The moose likes Servlets and the fly likes strange problem... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "strange problem..." Watch "strange problem..." New topic
Author

strange problem...

Chuan Ren
Ranch Hand

Joined: Aug 04, 2003
Posts: 42
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 ");
}
}
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

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.
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: strange problem...