tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Prashant sharma" <>
Subject Dynamically ready properties file or context path
Date Wed, 17 Apr 2002 11:40:17 GMT
Hi friends ... 

I want help regarding reading file from a servlet. 

I know i can use something like

But unfortunately when I try to use this in the following example i get 
as there i'm using static method and getServletContext is non static. 

And I want to stick to static method in this class  .. (correct me if i'm 

Now i just want to know how can i find another solution to it.
I want to dynamically read properties file (which has DB connection 

How shall i do it??? 

or how can i find $CATALINA_HOME in servlet.? 

Help is appreciated ... 

Thanking u,

If u've patience to read then 

Following is the code which i'm using... 

///  file start 

package com.fc.beans;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*; 

public class DB extends HttpServlet{ 

	public static String propertyFile= 
/// Above i've given the absolute path :-( 

	private DB(){

	public static Connection connect() throws SQLException{
		Error er=null;
			InputStream in=new FileInputStream(propertyFile);
			Properties p= new Properties();
			String driver=p.getProperty("jdbc.driver.class");
			String url=p.getProperty("jdbc.driver.url");
			String uid = p.getProperty("username");
			String pwd = p.getProperty("password");
			return DriverManager.getConnection(url,uid,pwd);
		catch(IOException e){
			er.log("Cannot read property file"+e.getMessage());
			throw new SQLException("Cannot read property file: "+e.getMessage());
		catch(ClassNotFoundException e){
			er.log("Cannot load driver"+e.getMessage());
			throw new SQLException("Cannot load driver: "+e.getMessage());

	public void main(String args[]) throws SQLException,Exception{
		System.out.println("Connected Successfully!");

////////////file end

To unsubscribe:   <>
For additional commands: <>
Troubles with the list: <>

View raw message