• 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
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
Bartenders:
  • Himai Minh
  • Carey Brown
  • Frits Walraven

How to get Username and password automatically

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to connect to the database. i want to get the username and password from the DSN and then use in my program. how can i do that?
 
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
What database type? How are you configuring your Data Source Name?
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iam not very clear with your question... my understanding is, you want to connect to the db using DSN (which has userid and password given) and then later get the username in your code after getting connected.

For this, you have to connect using the syntax:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dsn = "DSN_NAME";
String url = "jdbc dbc:" + dsn;
Connection con = DriverManager.getConnection(url);


To get the username in your program after getting connected to the db, you can use getUserName() of DatabaseMetaData interface.

Hope this is what you wanted...
 
Jyothi Lature
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ALternatively,
you could even use a Java properties file, say connect.properties, that helps you to set up your database connection at runtime.
It could have the following parameters in the form of name/value pair:

url=your_URL_here
# User name and password
user=scott
password=tiger

Then, after registering the driver, you could get these parameters from properties file to establish connection and as well have the userid/password available in your program code.
 
Ramesh Shanmugam
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jyothi Lature

This is what i wanted to know
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic