• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

to retrieve database username and password using jdbc

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic