[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

java program to connect to a datasaource in WAS 5.0.2

Hey,

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
Thanks
Achal
0
achaljalan
Asked:
achaljalan
  • 2
  • 2
  • 2
1 Solution
 
pluimCommented:
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?
0
 
petmagdyCommented:
did u defined the DS resource reference in ur Web.xml
0
 
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
            -arr
               - 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
      -addActivity.jsp
      -removeActivity.jsp

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...

Thanks
AJ

P.S -> WSAD and WAS are installed on diffenent computers
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
pluimCommented:
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".
0
 
achaljalanAuthor Commented:
Manage to sort it out... it was just because i dint define the resource in my web.xml
0
 
petmagdyCommented:
I guessed that, goood u managed it
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now