• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DataSource connection in WSAD 5.0

 
Michael Lipton
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic