• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

datasource question

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose I create a datasource and a JNDI name to access a database and I set up this in my application server websphere. In order for my java code to use this data source, do I have to deploy my java code to the application server ? I know if I do that that should work. But what if I just want to test some standalone java code which is not j2ee application ? for example I just want to test a select statement and print it on console, how can this code use the data source ? I assume the datasource is created on the application server so how can the standalone code access it ?
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
You can instantiate the InitialContext using a Properties object. You need to set few properties for getting the Context of the App server.
These are
1) InitialContextFactory Name
2) Provider URL
You might optionally need to pass the username/password as well.
Please check with your vendor documentation for the appropriate values of these properties.
Regards,
Amit
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by amit punekar:
Hi
You can instantiate the InitialContext using a Properties object. You need to set few properties for getting the Context of the App server.
These are
1) InitialContextFactory Name
2) Provider URL
You might optionally need to pass the username/password as well.
Please check with your vendor documentation for the appropriate values of these properties.
Regards,
Amit



Thanks Amit. So you think it is possible that I can isolate my java code from application server and it can still utilize the data source I set up on the server, correct ? That's my whole point.

secondly, why do I need user_id/password (I assume you referred to the id/pwd of database) ? I think if we use datasource the code only needs the JNDI name. Is that right ?
 
author & internet detective
Posts: 42160
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben,
I've seen some drivers that require a userid being passed to the datasource from the code. The password definitely shouldn't be required in the code.
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben,
I have used weblogic app server to access the data source from stand alone client where if I remember correctly I had passed username/pwd for connecting to the weblogic. And not for the Database. You are right as we have already provided credentials while creating datasource we should not be passing them again. But as Jeanne suggested there might be some special cases.
Also one more thing to note here that I could not get such thing running while using IBM Websphere server. If you run the stand alone client from within RAD as IBM Client app then it runs but from command prompt I never had luck. I tried setting number of Jars in the classpath but could not run it successfully.

Regards,
amit
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Amit. If you don't mind, could you share with us the few lines of your code that "connect to weblogic and access its datasource from outside of weblogic" ? I really have no clue how to do that. I never done that and can't find from google. Maybe everybody assumes the datasource is accessed from inside the server.

Thanks.
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben,
Here is the example snippet from BEA site.


And this is the link BEA Link - WLInitialContextFactory

Regds,
Amit
 
reply
    Bookmark Topic Watch Topic
  • New Topic