java program to connect to a datasaource in WAS 5.0.2

Posted on 2004-10-29
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
    LVL 4

    Expert Comment

    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

    did u defined the DS resource reference in ur Web.xml

    Author Comment


    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
    LVL 4

    Expert Comment

    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

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

    Expert Comment

    I guessed that, goood u managed it

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Product Review - Android Remix

    Come along for the ride with our Senior Product Manager, Brian Matis, as he reviews the Android Remix.

    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…
    This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
    This video Micro Tutorial is the first in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 ( But the ability to create custom scanning profiles al…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    933 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now