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?
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.