Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Obtaining Database password

 
Anirudh Vyas
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic