aspose file tools*
The moose likes Servlets and the fly likes Retrieve parameter value from a text file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Retrieve parameter value from a text file?" Watch "Retrieve parameter value from a text file?" New topic
Author

Retrieve parameter value from a text file?

Eric Wang
Greenhorn

Joined: Dec 21, 2000
Posts: 22
Hi, All:
I have few java program, they are using the same value for this three parameter.
1. this.driverName
2. this.conString
3. this.sql
this.driverName="oracle.jdbc.driver.OracleDriver";
this.conString="jdbc racle:thin:admin/user@backup..com.sg:1521 rcl";
this.sql="select * from Table1";
So I want to save this three parameter value in a text file, so every time I want to change it, I only need to change the text file, so all the java program will be change.
So how should I retrieve this parameter value from this text file? Or any other ways can slove this problem?

Thanks for all the replies.
cheers
Eric
Sathvathsan Sampath
Ranch Hand

Joined: Oct 03, 2000
Posts: 96
If you want to put your "name-value" paramters in a text file, then use the regular reader/writer methods to read/write to a text file. But, u should have some kind of a rigid format.
In case, these values are not going to change, u may use an interface & put all those values in that.
sathvathsan


- Sathvathsan Sampath
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
You can also use a properties file (text.properties). Simply create a text file with name/value pairs as such
driverName = oracle.jdbc.driver.OracleDriver
conString = jdbc racle:thin:admin/user@backup..com.sg:1521 rcl
sql = select * from Table1
Then save it with the extension ".properties" and restart you server (if you using servlets, for example). The Properties file also has to be in the path. I ussually put into a utilities package or somewhere like that. Then you can access the name/value pairs from within the program as such (assume we've named the file "myProperties.properties" and put it into "myPackage.util" directory)

It's nice to make this it's own little static utility method so you can simply call
String value = myUtils.getProperty("myKey");
The java classes you'll be interested in to explore and implement this are in the java.util package - specifically the java.util.ResourceBundle class. Don't forget that if you change the properties file you must restart the JVM or servet engine in order to see the changes take effect. I hope this helps.
Sean
Aru Ven
Ranch Hand

Joined: Sep 28, 2000
Posts: 199
Hi All,
I am new to JSp.... I need ur help. I have a oracle database.
I need to setup a connection from my servlet to the oracle database.
Oracle DB name = tstdb
loginname = user1
password = pswd.
Using the above parameters...
Can anyone help me how to make the connection to the database along with a small code of example.
thanks
Aruna
Eric Wang
Greenhorn

Joined: Dec 21, 2000
Posts: 22
Hi, Sean:
Thank you very much for the so detail explaintion. Thank you very much.
I have been slove my problem. Thanks again.
cheers
Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieve parameter value from a text file?