Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading username and password from a property file

 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

/*
--------------------------------------------------
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
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this the correct way to implement this?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic