This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieve parameter value from a text file?

 
Eric Wang
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Sean MacLean
author
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic