Also, if you are using a standard Java EE component (web/ejb), you can set the "authentication" mode <res-auth> to "Application" which indicates that the application will provide necessary credentials.
eg: you can specify the following in ejb-jar.xml / web.xml
<resource-ref>
<res-ref-name>DataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
By doing so, application can do component managed authentication as follows :
datasource.getConnection("user","password");
[Message sent by forum member 'jr158900' (Jagadish.Ramu_at_Sun.com)]
http://forums.java.net/jive/thread.jspa?messageID=386004