File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Websphere and the fly likes Getting DataSource object through JNDI in WebSphere 6.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "Getting DataSource object through JNDI in WebSphere 6.1" Watch "Getting DataSource object through JNDI in WebSphere 6.1" New topic

Getting DataSource object through JNDI in WebSphere 6.1

Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Hello friends,

I have to write a standalone java application which should get the DataSource object from WebSphere 6.1. DataSource object is of type oracle and is successfully configured in WebSphere's JNDI and I was able to TestConnection successfully. The standalone application is outside websphere context and is configured as a batch process which runs at scheduled time. This application should get the datasource object from JNDI and perform database operations.The main reason for doing this is I want to get rid of storing database credentials in properties file. I created a simple java project and added the following classpath libraries


The program in java file is as follows,

Problem: I want to use dataSource.getConnection() instead of dataSource.getConnection("username", "password"); because the later one involves hardcoding of username and password in java file. However when I invoke getConnection() it throws the following exception.

The datasource object configured in websphere has already been supplied username and password otherwise the testconnection would have failed. My question is why cant I use dataSource.getConnection() method instead of dataSource.getConnection("username", "password")?
If I supply the username and password to getConnection method then everything works fine. I can see the print statements on console.

Does anyone know the solution to this problem ?
Waiting for your reply.

Thank you,
I agree. Here's the link:
subject: Getting DataSource object through JNDI in WebSphere 6.1
It's not a secret anymore!