• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please Help w/ Error During DB Connection

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,




I'm very new to Java and WSAD 5.1. I have a database connection method that I can call from any other class "named method" with NO a problem. However, whenever I try to call the same database connection method from a "main" method within other classes, I get the following error.

********ERROR Starts********

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:652)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:255)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:292)
at javax.naming.InitialContext.lookup(InitialContext.java:359)
at com.ubs.mcs.oos.dao.RDBMSBaseDAO.getDatabaseConnection(RDBMSBaseDAO.java:51)
at com.ubs.mcs.oos.testClasses.testClassCall.main(testClassCall.java:30)
Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialSomething is wrong!!!

at com.ubs.mcs.oos.dao.RDBMSBaseDAO.getDatabaseConnection(RDBMSBaseDAO.java:60)
at com.ubs.mcs.oos.testClasses.testClassCall.main(testClassCall.java:30)

********ERROR ENDS********

Here is what my database connection method looks like:

********DB Connection Method Starts********
public synchronized Connection getDatabaseConnection(String appName)
throws DAOException {

String pool = appName + "Pool";
try {
javax.sql.DataSource ds = (javax.sql.DataSource) getInitialContext().lookup(pool);
Connection conn = ds.getConnection();
return conn;
} catch (Exception e){
e.printStackTrace();
throw new DAOException(e);
}
}
********DB Connection Method ENDS********

********Call to DB Connection Method from w/i Main method of another class.

conn = getElems.getDatabaseConnection(mesRes.getMessage("appID.acronym"));



I appreciate any help provided.

Thanks,
Lulu
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
InitialContext are mostly used in a J2EE environment. I think, because you are using a main method, you are now using a J2SE application. To use the InitialContext in a J2SE enviroment you must append j2eeclient.jar in your classpath. I believe it is j2eeclient.jar. I can't verify it because I'm now working on a computer without WSAD.
 
Oh. Hi guys! Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic