Thank you all for your help. I think I got it working the way I expected.
Here is the code I use to get the database connection:
public class MyConnection() extends ConnectionBean {
public MyConnection() {
super();
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
Context context = new InitialContext(env);
DataSource datasource = (DataSource)
context.lookup("jdbc/MySource");
super.setConnection(datasource.getConnection("user", "password"));
context.close();
}
}
I think I still have some reading to do to fully understand how it works
behind the scenes, but it works for now. We have a custom web application
that was written before I started at the company, so I'm not used to having
to manage the connections.
I was just passing the MyConnection() object to all the classes I needed it,
but it just seemed so messy. I knew there had to be a better way, and
through the help of you all I think I found it, so THANK YOU!
James R. Perkins
P.S.
I think the way I am using the user and password is probably not the
best/safest. That will be the first thing I start researching for a way to
secure that.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.