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

Creating Datasource

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I have create DataSource and JNDI name WSAD5.1

Datasource name is MyDataSource and jndi name is jdbc/LoginDS.
following code is working properly.
below is my database connection code:
public Connection getConnection() throws SQLException,NamingException{
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup ("jdbc/LoginDS");
Connection con = ds.getConnection("scott","tiger");
return con;

I lookup using java:comp/env/jdbc/LoginDS
that's not working .
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33111


We're pleased to have you here with us in the IBM/Websphere forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Forum Bartender

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Martin Lira
Ranch Hand

Joined: May 26, 2004
Posts: 97
You need to create a resource reference (java:comp/env/jdbc/LoginDS)in you web deployment descriptor that refers to the jndi name jdbc/LoginDS

I agree. Here's the link:
subject: Creating Datasource
It's not a secret anymore!