my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes querying for password from java.sql.Connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "querying for password from java.sql.Connection" Watch "querying for password from java.sql.Connection" New topic

querying for password from java.sql.Connection

Rhea Karnam

Joined: May 06, 2003
Posts: 21
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

Joined: Jan 29, 2002
Posts: 62
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

Joined: Feb 02, 2002
Posts: 1211

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.

The future is here. It's just not evenly distributed yet. - William Gibson
Sonny Gill LinkedIn
I agree. Here's the link:
subject: querying for password from java.sql.Connection
It's not a secret anymore!