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?
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
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
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
Joined: Dec 21, 2000
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