aspose file tools*
The moose likes Websphere and the fly likes Content.INITIAL_CONTEXT_FACTORY Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "Content.INITIAL_CONTEXT_FACTORY" Watch "Content.INITIAL_CONTEXT_FACTORY" New topic
Author

Content.INITIAL_CONTEXT_FACTORY

Shireen
Greenhorn

Joined: Jan 03, 2002
Posts: 7
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

Joined: Aug 19, 2000
Posts: 184
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

Joined: Jan 03, 2002
Posts: 7
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

Joined: Mar 08, 2001
Posts: 13
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

Joined: Jan 03, 2002
Posts: 7
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

Joined: Aug 19, 2000
Posts: 184
Good that you solved the problem, congrats.
 
 
subject: Content.INITIAL_CONTEXT_FACTORY