This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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.
Joined: Oct 23, 2006
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 ...
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.