• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Content.INITIAL_CONTEXT_FACTORY

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am new to WebSphere. I have copied a java source from the IBM web site so that I can access the naming system and get a database connection using the WebSphere Application Server 4.0, but when I compile the .java, I got two errors from the compiler.
1. Variable "Context/INITAIL_CONTEXT_FACTORY" is not defined in the current context.
2. Cannot find type "javax/naming/Context"

----------------------------------Start
The following is the code fragment:

private final String DATASOURCE = "ABC";
public Connection getConnection()
{
Connection conn = null;
try
{
java.util.Properties parms = new java.util.Properties();
parms.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
// access naming system
javax.naming.Context context = new javax.naming.InitialContext(parms);
// get DataSource factory object from naming system
Ds = (javax.sql.DataSource)context.lookup(DATASOURCE);
conn = ds.getConnection();
return conn;
}
catch (Exception t)
{
// DataSource not found. Throw Exception
}
-------------------------------End
I guess it has something to do with the Classpath setting, I did include most of the jar files in the classpath. However, I have no idea as to what jar files are needed here for the "Context".
Could anyone tell me what should I do to solve this compilation error. Thanks.
 
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shireen,
First of all check whether you do have a datasource named ABC in WAS through the admin console, if not then u need to create one. The files ull need are ujc.jar for the naming classes.
Regards,
Daman
 
Shireen
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by daman sidhu:
Shireen,
First of all check whether you do have a datasource named ABC in WAS through the admin console, if not then u need to create one. The files ull need are ujc.jar for the naming classes.
Regards,
Daman


Daman,
Thanks for the reply. I did create ABC with WAS and I did have ujc.jar in my CLASSPATH. Is there any other possibilities that cause this problem?
Shireen
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shireen,
did you include set the j2ee.jar file in your classpath?
It can be found in the lib subdirectory of the WebSphere installation, for example D:\WebSphere\AppServer\lib\
Are using this code in a client application or in a component running in a WebSphere container i.e. servlet, EJB? When you run in WebSphere itself you can use the default constructor of InitialContext.
Greeting
Sander Fieten
[This message has been edited by Sander Fieten (edited January 03, 2002).]
 
Shireen
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daman,
Thanks anyway. I think I know why. There are two ujc.jar on my server. One is under /opt/WebSphere/AppServer/lib and the other is under /opt/WebSphere/AppServer/deploytool/itp.....
I had included the former, but the later was what it needed.
Shireen
 
daman sidhu
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good that you solved the problem, congrats.
 
bacon. tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic