We help IT Professionals succeed at work.
Get Started

JNDI problem when run at java server-side

chinsw
chinsw asked
on
488 Views
Last Modified: 2013-11-24
In my project,I'm using Tomcat 5.0 to configure the JNDI connection.When I run at webpage,it works fine.But,when I run at java server-side (through Main() object), I can;t connect to DB,it will hit error when come to this logic :

Context envContext = (Context) initContext.lookup("java:/comp/env");

And it returns error like this :

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.initial
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
        at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at my.com.eprotea.common.db.DBConnManager.<init>(DBConnManager.java:45)
        at my.com.eprotea.common.db.DBConnManager.main(DBConnManager.java:65)

Anyone can help me to solve this problem?I need to run in backend process.thx anyway.
Comment
Watch Question
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE