JDBC and user security

I'm making a big application. What is the best way to pass the user name and password between all objects?
RdeLangeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LEGANDOCommented:
You can store them in a Session.
boonlengCommented:
Why you want to pass the user name and password to all the objects?
If you want to use the user name and password to connect to database, I would suggest that you setup datasource at the application server and get the connection from datasource instead of opening jdbc connection.

Regards,
Boon Leng
RdeLangeAuthor Commented:
Could you give me an example of that?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

boonlengCommented:
What server are you using and what type of application are you building.. swing, web..ect?
May be you can tell us more what you trying to do.
RdeLangeAuthor Commented:
I planning to use Websphere and for my own JBoss
boonlengCommented:
For JBoss, you can refer to JBoss Getting Started Guide - Chapter 8 on how to setup datasource.
http://www.jboss.com/products/jbossas/docs

As for Websphere, you can refer to the following redbook for WSAD and WAS: http://publib-b.boulder.ibm.com/abstracts/sg246957.html?Open
http://publib-b.boulder.ibm.com/abstracts/sg246195.html?Open

After setup the datasource, you can retrive the connection by looking up the jndi name:

    InitialContext initContext = new InitialContext();
    DataSource dataSource = (DataSource) initContext.lookup("jdbc/mydatabaseDS");
    Connection conn = dataSource.getConnection();

You can improve the above code by implmenting it into ServiceLocator and cache the datasource, so that application dont need to lookup the datasource everytime requesting the connection. http://java.sun.com/blueprints/corej2eepatterns/Patterns/ServiceLocator.html

Hope this will help.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.