File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "DataSource connection in WSAD 5.0" Watch "DataSource connection in WSAD 5.0" New topic
Author

DataSource connection in WSAD 5.0

Michael Lipton
Greenhorn

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;

try
{
initial = new InitialContext();
ds = (DataSource) initial.lookup("java:comp/env/xroller");
}
catch (NamingException e1)
{
e1.printStackTrace();
}
************************
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(NamingManager.java:652)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:255)
atjavax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:292)
at javax.naming.InitialContext.lookup(InitialContext.java:359

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.
Thanks,
Mike
Madan Kulkarni
Greenhorn

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", "com.ibm.ejs.ns.jndi.CNInitialContextFactory");
InitialContext initialcontext = new InitialContext(properties);
ds= (DataSource)initialcontext.lookup(str_dsName);//str_dsName=JNDI Name


Java Programmer
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DataSource connection in WSAD 5.0
 
Similar Threads
How can I run an applet for accessing the PC camera
JNDI Access Problem
Error while getting Datasource object
problem in creating mysql datasource on weblogic 10.3.4
Datasource JNDI Lookup in WSAD from standalone app