File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes to retrieve database username and password using jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "to retrieve database username and password using jdbc" Watch "to retrieve database username and password using jdbc" New topic
Author

to retrieve database username and password using jdbc

siva sankar
Ranch Hand

Joined: Jul 13, 2006
Posts: 68
Hi,
It is easy to get connecting to any database using username and password which is already known to us,

eg: Class.forName("org.postgresql.DriverManager");
Connection con = DriverManager.getConnection("jdbc:postgresql://URL","infinity","infinity");

please help me how to print the username and password which is used in getting connection(Connection class).
Please specify the method to retrieve those values.
Thanks In Advance
siva sankar
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

How do you connect to a database without already knowing these? Or are you asking how to query the credentials of a particular database user other than the one you connected with?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
Are you saying that you have an open Connection object and you want the username and password that were used when opening the connection?

There are no standard methods on the Connection object or DriverManager that will provide that. I scanned the Postgresql driver javadoc and didn't see a Postgresql-specific method either.

You'll need to get it from whatever object gave it to the DriverManager.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30894
    
158

Siva,
I can't imagine that there would be a public API to get the password. This would mean that any code with access to a connection or datasource could get the user's credentials. I think you will have more luck intercepting this information from where the connection is created.

If you explain further what you are trying to accomplish, you may get a more useful answer.


[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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: to retrieve database username and password using jdbc