aspose file tools*
The moose likes JDBC and the fly likes Obtaining Database password Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Obtaining Database password" Watch "Obtaining Database password" New topic
Author

Obtaining Database password

Anirudh Vyas
Ranch Hand

Joined: Oct 23, 2006
Posts: 93
Hi,

I am trying to do dataSourceInstance.getConnection().getMetaData( ) and i see only getUserName( ), getConnectionURL( ). I do not however see a getPassword( ); is there any way i can obtain database password at runtime?

For curious, i need to pass the user name and password into some external library method that uses it.

Any help in this regard would be appreciable.

Regards
Vyas, Anirudh


Vyas, Anirudh
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
A password is a sort of write-only attribute. You enter it and it is hashed with MD5 or similar, then you cannot retrieve it.
Anirudh Vyas
Ranch Hand

Joined: Oct 23, 2006
Posts: 93
Well; it begs the question doesn't it? connection URL can contain the user name and password; you could parse the connection URL to retrieve password; but that solution is *Yuk!* (which would be my final stab at it).

Any other suggestions? I could save user and pwd info in properties file, but dont wanna do that; because if i do that, now i got so many things to worry about, because a data source is gotten by service locator using JNDI lookup; The data source aligns with data source used by application throughout. Now if i change something i gotta go and change this properties file up there ...


Regards
Vyas, Anirudh
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Originally posted by Anirudh Vyas:
Well; it begs the question doesn't it? connection URL can contain the user name and password; you could parse the connection URL to retrieve password

Only if you pass the password that way. Most people don't for security reasons. I recommend putting the password somewhere you can get to it. Preferably in an encrypted property file. This is preferable than the program trying to parse it as nobody can get their hands on the actual password.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Obtaining Database password
 
Similar Threads
Problems setting up was administration db2-database for Websphere4.0
How to get back the Access MDB file password?`
how to get input from javascript and pass to servlet
Communications link failure
How to store passwords securly