• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Standalone java app conneting through JNDI

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I apologise if I say something stupid here since I have no experience in EJB. I have a standalone java program that reads an excel workbook, converts it to XML and then inserts the XML data into database. Now I have been able to connect to the Oracle database using thin driver and URL.
The client has Webspeher running on the machine where this standalone application would reside (note that the app would *not* be deployed on WAS, it would be on the same *machine*). Since the App server already has a pool to the same database I want to use to use the same using JNDI. How can I use the JNDI? My code looks something like this:

Currently the code is on my machine while the WAS is running on some other machine on our LAN. I am getting error javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory probably beacuse I do not have the classes for JNDI here on my machine.
My questions are:
(1) Is it possible for a stand-alone java program to connect to a remote database using JNDI?
(2) If yes does the program need to have the jar containing the "WsnInitialContextFactory" on client machine as well?
(3) Should this application be put somewhere inside folder of WAS which are in classpath (say bin or something), will then only it run?
I would really appreciate your replies. Thanks for your valuable time.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you will need to refer to some of the WebSphere JARs. You don't have to put your app in the same directory as WebSphere, just make sure the JARs are on the client's classpath.
One extra ponter to save you a lot of time: If your app server is running using the IBM JRE, make sure th client does as well. If you mix the IBM and SUN JRE's for RMI work they fail to communicate.
Dave
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yash,Use File System Context for JNDI Lookup.In that case you will not be bind with Websphere bunch of jar files.
 
Yash Sharma
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To test things I copied my application folder inside the bin sub-folder on WAS application folder. I added the required jar (ns.jar) in application's classpath but now I am getting a NullPointerException when I do a lookup as under.

Also are there any good tutorials on using the "File System Context" for JNDI Lookup?
Thanks a lot again.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic