• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.util.properties and JSP

 
d frazier
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the scoop: Apache / Tomcat config.
I'm trying a simple test to prevent from hard coding my database connection info into my classes. I jave a JSP that initializes the class:
...
props p = new props();
//show a little help message
System.out.println("success");
...
Soooo...
I have prop.properties file that contains the variables I wanted to set(see following snippet).
The important part of the class is:
Properties p = new Properties();
p.load(new FileInputStream("props.properties"));
uid = p.getProperty("uid");
pswd = p.getProperty("pswd");
hostnam = p.getProperty("hostnam");
sid = p.getProperty("sid");
port = p.getProperty("port");
dbnam = p.getProperty("dbnam");
//to test iff I get a good connection...
System.out.println("jdbc racle:thin:" + uid +"/" + pswd +"@" +hostnam + ":" + port + ":" + sid);
No matter what I try, I've ended up with "file not found". I've put the props file just about everywhere, changed the classpath, etc.
Any ideas would be helpful (I'm supposing this is the classic "eye-D-ten-T" error, needing some enlightenment).
-much appreciation
Dane
 
d frazier
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it seems that I've answered my own question...
After checking the classpath, several times, I figured a rename of my objects, and some twisting of the IS stuff from what I had might work, combine that with six different ways from six different books...
Here's what I found that worked (FYI - all this does for the moment is print to sys out).
public mycon()
{
InputStream is = getClass().getResourceAsStream("/mycon.properties");
Properties dbProps = new Properties();
try
{
dbProps.load(is);
/*old code
Properties p = new Properties();
p.load(new FileInputStream("\mycon.properties"));
*/
uid = dbProps.getProperty("uid");
pswd = dbProps.getProperty("pswd");
hostnam = dbProps.getProperty("hostnam");
sid = dbProps.getProperty("sid");
port = dbProps.getProperty("port");
dbnam = dbProps.getProperty("dbnam");

System.out.println("jdbc racle:thin:" + uid +"/" + pswd +"@" +hostnam + ":" + port + ":" + sid);
}
catch (IOException e)
{
System.out.println("mycon exception thrown!" + e);
}
}
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may be a moot point now, but I'm going to move this to the Servlets/JSP forum, where it's more on-topic.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!