If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > Cannot instanciate com.ibm.websphere.naming.WsnInitialContextFactory

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-03-06, 00:19
harrypeh harrypeh is offline
Registered User
 
Join Date: Sep 2006
Posts: 2
Cannot instanciate com.ibm.websphere.naming.WsnInitialContextFactory

Hi all,

I would like to connect remotely to the DB2 in linux machine using the JNDI lookup.

In websphere development 5.1, this portion of code is working in 5.1 env :

/////////////////////////////////////////////////////////////////////////
Context MyCtx = null;
DataSource MyDS = null;
Hashtable parms = new Hashtable();
Connection conn = null;

parms.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFac tory ");

MyCtx = new InitialContext(parms);
MyDS = (DataSource) MyCtx.lookup("jdbc/Employee");
conn = MyDS.getConnection();

/////////////////////////////////////////////////////////////////////////

But after i recompile in websphere rational 6.0 in windows XP env, the code is not working anymore. It said :

=> Cannot instanciate com.ibm.websphere.naming.WsnInitialContextFactory. .

I have imported the db2jcc.jar, db2jcc_license_cu.jar, can anyone giv me some clue what is happening? Thanks alot.
Reply With Quote
  #2 (permalink)  
Old 09-09-06, 02:51
jwenting jwenting is offline
Registered User
 
Join Date: Apr 2003
Posts: 40
This is how to do it using SJSAS, I'm confident it will work with any server by supplying the correct URI and port numbers (and of course including the correct jars in your classpath):

Quote:

1. Add three Java archives (JARs) to your class path in the lib directory of Application Server's root installation directory: j2ee.jar, appserv-rt.jar, and appserv-admin.jar.
2. Set the values for the Java virtual machine startup options, as follows:

jvmarg value = "-Dorg.omg.CORBA.ORBInitialHost=${ORBhost}"
jvmarg value = "-Dorg.omg.CORBA.ORBInitialPort=${ORBport}"

where ORBhost is Application Server's host name and ORBport is the ORB port number, whose default is 3700 for the default instance. You can obtain that information from the domain.xml file on the remote system. For details on that file, see Chapter 1 in Sun Java System Application Server Enterprise Edition 8.1 Administration Reference.
Here is an example of the compilation command line (all on one line):
java -classpath.;c:\Sun\AppServer.ib\j2ee.jar;c:\Sun\App Server.ib\appservrt.jar;c:\Sun\AppServer.ib\appser v-admin.jar-Dorg.omg.CORBA.ORBInitialHost=localhost-Dorg.omg.CORBA.ORBInitialPort=3700 MEJBStandaloneClient ejb/mgmt/MEJB
This looks up EJB resources, but JDBC resources should be no different.

I've seen a lot of people trying what you did (and tried it myself just on the off chance it might work and to see why it didn't).
It's not only something that (generally) won't work (might work inside the container but don't count on it) but it's bad programming practice as it introduces a hard dependency on a specific appserver.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On