datasource question

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 ?

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

Regards,
Amit

ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 375

posted Jan 10, 2008 20:31:00

0

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 ?

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

Joined: Mar 28, 2006
Posts: 375

posted Jan 11, 2008 14:53:00

0

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.