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