java program to connect to a datasaource in WAS 5.0.2


I have DB2 8.1 and create a database, ARRT, with 2 tables.

The datasource that i have configured in WAS 5.0.2 connects to the database fine, as the test connection works successfully. The datasource uses the DB2 JDBC DRIVER.

I have a java program that needs to connect to the datasource and extract some information that can be displayed on a browser through a jsp. To create the connection to the datasource I used the following code

                  InitialContext ic = new InitialContext();
                  DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/ARRT");
                  con =  ds.getConnection();

but it didnt work. Is there something I am missing or is there a simpler way to do this.

Help will be greatly appreciated
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.

Are you getting an error, or does the datasource lookup simply fail?

You mention you're using a (standalone?) java program to connect to the datasource, but you're displaying it in a JSP. More to the point, are you connecting to the datasource inside WAS or outside?
did u defined the DS resource reference in ur Web.xml

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
achaljalanAuthor Commented:

To better explain the scenario, I am new to WSAD and WAS.

I developed a application in WSAD and it works fine, connects to DB, retrieves information and add information to the databse. My files in WSAD have the following tree structure..

- ARRTweb
   - Web Site Navigation
   - Web Deployment Descriptor
   - Java Resources
      - arr.dbconnect
         - DbConnect
         - AddToDb
      - arr.servelets
         - addActivity
         - removeActivity
   - WebContent
      - Meta INF
      - theme
      - Web INF
         - classes
               - dbconnect
                  - DbConnect
                  - AddToDb
               - servelets
                  - addActivity
                  - removeActivity
         - databases
            - ARRT.dbxmi
            - ARRT_SCHEMA2.schxmi
            - ARRT_SCHEMA2_EMPDETAILS.tblxmi
         - lib
         - ibm-web-bnd.xmi
         - ibm-web-ext.xmi
         - web.xml

all of this is part of ARRT.ear

now what happens in the program is that, addActivity.jsp fires up first extracting names from the databse and allows changes while remove activity just removes a record...

everything works fine in the WSAD 5.1 ... but exporitng ARRT.ear and installing it as a new application on the WAS 5.0.2 does not connect to the datasource. The datasource (jndi - jdbc/ARRT) connects successfully to the databse in a test connection. The addActivity page loads up without any names.

All the options in WAS are default and I generated a default binding when installing the ear.

I am not getting any error... i think the datasource lookup just fails.
How do I define a DS resource reference in Web.xml

Any help will be greatly apprecaited...


P.S -> WSAD and WAS are installed on diffenent computers
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Does addActivity.jsp produce an error message? Regardless of whether the JNDI lookup fails or it can't connect to the database, there should be some sort of error message.

If there are no errors at all and the list of names is simply blank, try executing a different SQL statement to confirm the connection, e.g. "values (1)" or "select count(*) from syscat.tables".
achaljalanAuthor Commented:
Manage to sort it out... it was just because i dint define the resource in my web.xml
I guessed that, goood u managed it
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 App Servers

From novice to tech pro — start learning today.