Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

querying for password from java.sql.Connection

 
Rhea Karnam
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I obtain a Connection object to my Database thru JDBC, where the connection properties come from an external prop file.
I also have to call another java program within my code, passing in the connection details (like dbname, username, password etc.).
I figured out that i can get the user name, dbname, etc from the connection's meta data. But, what I can't manage is to find a way to extract the password detail from the Connection object.

My Questions are:
1. Am I doing the right thing in trying to extract the password details from the Connection object?
2.Is there some other way I can get the password info, in my code (other than accessing the props file)?
Can somebody help me out?
 
Napa Sreedhar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not a good idea to get database connection meta-data .
Instead use the properties file to get a new database connection.

Common database activities like get connection can be put in a static final class.
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would be very much worried if you were allowed to get the password information from the Connection. There are definately no methods for doing so in DatabaseMetaData.

Originally posted by Napa Sreedhar:
Common database activities like get connection can be put in a static final class.


Better still, try to learn how to use a javax.sql.DataSource to manage your connections. DataSource(s) can be used both in web and standalone applications, and are the standard J2EE/Java way of managing multiple connections.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic