Closed Thread Icon

Topic awaiting preservation: Anyone has example to keep db info in a .properties file in servlet? Pages that link to <a href="http://ozoneasylum.com/backlink?for=12906" title="Pages that link to Topic awaiting preservation: Anyone has example to keep db info in a .properties file in servlet?" rel="nofollow" >Topic awaiting preservation: Anyone has example to keep db info in a .properties file in servlet?\

 
Author Thread
Pimms One
Bipolar (III) Inmate

From: Australia
Insane since: Jun 2003

posted posted 09-25-2003 06:16

I am learning JSP/Server and was using connection pooling for database connection using Java servlet. The database information are in the servlet. Can you please tell me how I could make these info in a properties files (for example configuration.properties) which I could edit externally so that I won't have to recompile my servlet each time I change the database password?

There is an example in c13 of http://www.cookconsulting.com/MasteringJSP/MJspSrc.zip

But I could n't make it work after trying for a few days. Can you please help me? (I am able to test the PropStore, it's working. But not sure how to test the ConnectionManager.java).

Thank you.



InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 09-25-2003 13:03

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Rhino
Bipolar (III) Inmate

From: New Jersey, USA
Insane since: Jul 2003

posted posted 09-25-2003 13:50

Since the properties file is just a test file..I have my connection info listed as the following

dbDriverClass=com.microsoft.jdbc.sqlserver.SQLServerDriver
dbConnectionString=jdbc:microsoft:sqlserver://rhino:1433;databasename=Test;SelectMethod=Cursor
dbUser=user
dbPassword=tryandguess


These can be retrieved with the Properties object with a simple call

String user_name = properties.getProperty("dbUser");
String password = properties.getProperty("dbPassword");

etc....


this will give you the values you are looking for to create the connection.


Hope this is what you were looking for



Pimms One
Bipolar (III) Inmate

From: Australia
Insane since: Jun 2003

posted posted 09-26-2003 02:34

Rhino,

What you have mentioned is exactly what I needed. I wonder if you could give me some sample code. I was thinking to have say database.properties and a servlet (connectionManager.java) that reads from thie properties file.

Thank you.

Rhino
Bipolar (III) Inmate

From: New Jersey, USA
Insane since: Jul 2003

posted posted 09-26-2003 13:23

Properties properties = new Properties();
FileInputStream in = new FileInputStream("database.properties");
properties.load(in);

driverClass = properties.getProperty("dbDriverClass");
connectionString = properties.getProperty("dbConnectionString");
user = properties.getProperty("dbUser");
password = properties.getProperty("dbPassword");

Class.forName(driverClass);

Connection con = DriverManager.getConnection(connectionString, user, password);


You call also find more methods and info at http://java.sun.com and search for "Properties"

Hope this helps..



« BackwardsOnwards »

Show Forum Drop Down Menu