Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


java program to connect to a datasaource in WAS 5.0.2

Posted on 2004-10-29
Medium Priority
Last Modified: 2013-12-10

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
Question by:achaljalan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2

Expert Comment

ID: 12445587
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?
LVL 13

Accepted Solution

petmagdy earned 500 total points
ID: 12446446
did u defined the DS resource reference in ur Web.xml

Author Comment

ID: 12461673

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 12464422
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".

Author Comment

ID: 12464867
Manage to sort it out... it was just because i dint define the resource in my web.xml
LVL 13

Expert Comment

ID: 12467815
I guessed that, goood u managed it

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Configure Web Service (server application) I. Configure security for Web Services methods First, we need to protect Session bean which implements the service: 1. Open EJB deployment descriptor (ejb-jar.xml) in the EJB project that contains you…
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question