| | |
db configuration file
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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---
import java.sql.DriverManager;
import java.sql.Connection;
import java.util.Properties;
import java.io.*;
public class DbConfiguration{
String jdbcDriver="oracle.jdbc.driver.OracleDriver";
String connectionURLThin="jdbc:oracle:thin
10.192.4.215:1521:AIPUAT1";
String DbUserId="trn1";
String DbUserpassword="trn1";
public void classForName() {
String jdbcDriver;
String connectionURLThin;
String DbUserId;
String DbUserpassword;
Connection con = null;
Properties prop=new Properties();
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).
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---
import java.sql.DriverManager;
import java.sql.Connection;
import java.util.Properties;
import java.io.*;
public class DbConfiguration{
String jdbcDriver="oracle.jdbc.driver.OracleDriver";
String connectionURLThin="jdbc:oracle:thin
10.192.4.215:1521:AIPUAT1";String DbUserId="trn1";
String DbUserpassword="trn1";
public void classForName() {
String jdbcDriver;
String connectionURLThin;
String DbUserId;
String DbUserpassword;
Connection con = null;
Properties prop=new Properties();
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).
Last edited by Ankita B; Feb 18th, 2008 at 5:53 am.
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
props.load(new FileInputStream("dbConnection.properties"));
When you make changes in your .properties files, you must restart the server
Check out my New Bike at my Public Profile at the "About Me" tab
Use: double '\': '\\'
or single '/'
or single '/'
Check out my New Bike at my Public Profile at the "About Me" tab
![]() |
Similar Threads
- parsing conf file in c++ (C++)
- Unrecognized configuration section 'forms' (ASP.NET)
- xml web configuration file (C#)
- configuration file (C++)
- Configuration Errors (ASP.NET)
- Explanation of Process File (Java)
- php.ini file not being read (PHP)
- system crashes,gets slow, and network gets down,Hijacklog file pvded (Viruses, Spyware and other Nasties)
- Debian Linux xserver configuration (Window and Desktop Managers)
Other Threads in the Java Forum
- Previous Thread: function code executing twice!
- Next Thread: how to get windows login username into struts?
Views: 1377 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application apps arguments array arrays automation binary bluetooth businessintelligence card chat class classes client code collision component crashcourse database draw eclipse ee error event exception file fractal free game gis givemetehcodez graphics gui helpwithhomework html ide image input integer integration j2me java javadoc javafx javaprojects jmf jni jpanel julia jvm linux list loop machine map method methods migrate mobile netbeans newbie nls number object oracle physics print problem program programming project radio recursion scanner screen security server service set size sms socket software sort sql string swing test textfield threads time transfer tree trolltech utility windows






