Hi,I wish to make a configuration file for db connection parameters.
I read about properties file.I have made a properties file that contains the following info---

String jdbcDriver="oracle.jdbc.driver.OracleDriver";
String connectionURLThin="jdbc:oracle:thin:@ hostname:AIPUAT1";
String DbUserId="abc";
String DbUserpassword="abc";

and saved it as DbConnection.properties.

i have also made a java file that uses these properties as---

try {


props.load(new FileInputStream("dbConnection.properties"));
jdbcDriver=props.getProperty("jdbcDriver");
System.out.println(jdbcDriver);



connectionURLThin=props.getProperty("connectionURLThin");
System.out.println(connectionURLThin);



DbUserId=props.getProperty("DbUserId");
System.out.println(DbUserId);



DbUserpassword=props.getProperty("DbUserpassword");
System.out.println(DbUserpassword);



Class.forName(jdbcDriver);


con=DriverManager.getConnection(connectionURLThin,DbUserId,DbUserpassword);


}


catch(Exception e){
e.printStackTrace();
}


}


public static void main(String[] args)
throws java.lang.InterruptedException {


DbConfiguration dbc = new DbConfiguration();


dbc.classForName();
}


}

i am developing a web based application using java and jsp.I have placed my files in webapps folder.Where should i put properties file?.. wt else needs tp be put in the java code?..and how should i lonk this so that other java files can make use of properties(even after being changed).

Put it wherever you want, as long as you say in your code where is it so you can read it:
props.load(new FileInputStream("dbConnection.properties"));
When you make changes in your .properties files, you must restart the server

ok thx..i put it directle in C: drive but when i give
props.load(new FileInputStream("C:\dbConnection.properties"));

im gettin compile time error --illegal escape character '\'...

Use: double '\': '\\'
or single '/'

yup got it!..thx..:)

i used this properties file in my old java file.it takes value from properties file but is giving classNotFoundException..However when i use same driver ,url etc directly in the java class itself and not thru prop,it runs perfectly fine.i have set classpath etc too..what cud be wrong ere?..

maybe your application is not expecting to find what you want it to find :)
mistakes are common you know, is pretty hard though, to try and figure out what the problem is, without having a look at the code that produces the actual Exception

i found the error..had put driver etc names in the properties file under quotes..which is not required..

commented: may it be her problem, she shares the sollution with the rest of the community +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.