Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Content.INITIAL_CONTEXT_FACTORY

 
Shireen
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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.
 
daman sidhu
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Sander Fieten
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Good that you solved the problem, congrats.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic