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

DataSource connection in WSAD 5.0

Michael Lipton

Joined: Jul 22, 2004
Posts: 5
I created a Java applet with the following code to connect to a DB2 database.
Context initial = null;
DataSource ds= null;

initial = new InitialContext();
ds = (DataSource) initial.lookup("java:comp/env/xroller");
catch (NamingException e1)
However, I'm now trying to use the same code in a Java application, and i'm getting the following exception:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialat javax.naming.spi.NamingManager.getInitialContext(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.lookup(

I'm at a loss for why this is happening since it works fine in the applet, does anyone have any ideas.
I really appreciate anyone's help.
Madan Kulkarni

Joined: Sep 23, 2002
Posts: 5
Try this:

Properties properties = new Properties();
properties.put("java.naming.provider.url", "iiop://localhost");
properties.setProperty("java.naming.factory.initial", "");
InitialContext initialcontext = new InitialContext(properties);
ds= (DataSource)initialcontext.lookup(str_dsName);//str_dsName=JNDI Name

Java Programmer
I agree. Here's the link:
subject: DataSource connection in WSAD 5.0
It's not a secret anymore!