• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

DataSource connection in WSAD 5.0

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic