aspose file tools*
The moose likes JDBC and the fly likes reading username and password from a property file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "reading username and password from a property file" Watch "reading username and password from a property file" New topic
Author

reading username and password from a property file

Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
hi!
Is it possible to replace part of all the the information between the brackets in the following line:
con=DriverManager.getConnection("jdbc: oracle:thin@ott46:1521:d10h", "inv_read", "invdev1");
I would need to keep all the connection information, or at least the username and password, in a seperate property file and read the information from there when needed. How do I do this?
Thanks,
Annette
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974

/*
--------------------------------------------------
Sample db.properties file:
db.driver=sun.jdbc.odbc.JdbcOdbcDriver
db.user=DBA
db.password=SQL
db.url=jdbcdbc:Titan
*/

------------------
Moderator of the JDBC Forum


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
Thanks!
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
Is this the correct way to implement this?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Yes, except it should be stmt=connection.createStatement();
In our implementation, the connectoToDatabase() method is in a shared class that can be used by anyone who needs JDBC access. That is why we are using a database properties file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reading username and password from a property file