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.

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.