• 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

problem in getting the database connection from a connection pool

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai All,

I am facing a problem in getting the database connection from a connection pool created on weblogic server 8.1.

I am using the Oracle database 8.1.7.

I have configured my connection pool, datasource and JNDI in weblogic.
In my java program i have the following code to retrieve the connection.




The above code is working fine but, the two ht.put statements are creating problem.
The problem is, after converting the application into WAR file it can be deployed
on any machine or different port on same machine. My application fails if its deployed on
weglogicserver which is at different port.

Is there any way that i can get rid of those ht.put statements or any other way to solve the problem.
any help is appreciated.
Thanks in advance
Pooja.
 
author & internet detective
Posts: 41860
908
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
Pooja,
You can use a properties file to get the port.

I'm moving this to the EJB/J2EE technology forum since the question is about getting an initial context. The people there might have a better answer.
 
Pooja Agarwal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking for some help !!!
Any help is appreciated.

Thanks
Pooja
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pooja

You can offcourse get rid of ht.put statements.

If you want to get rid of those statements you will have to specify the properties at the run time.

Use the -D command to set the properties in this way -Dproperty=value at the startup time.

I hope this answers your query.

Cheers
Ankur
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a client program which needs to access container provided services then unfortunately you need to tell the client how to get these services. So you will always have to put the Initial Context properties somewhere - Ankur Srivastava's suggetsion is sensible: move hard-coded configuration strings out of you code and into a config file or a VM param.
 
Pooja Agarwal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai Ankur and Paul,

Thanks for ur replies.
Can u plz let me know how to set VM param or use config file inorder to set these properties. I am struggling as i am new to weblogic and connection pooling concept.

So after making the WAR file if the port is changed i have to mention that in the config file so that my java code reads the port from config file. And there is no way with out which it can get the port number.

For connection pooling in weblogic are these parameters a must?. This question seems to be stupid after all these explanation but i have seen some code where there is nothing related to those ht.put() statements but still the code works fine. No config file or VM params. Is what i have seen is true.

Thanks a lot and i appreciate ur help.
Pooja.
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Context parameters are a must - they should be made available. Not always through the code though - if the application you are running already has a context, it would take up the default context that is available.
We have an application that runs within the scope of Weblogic server - no context parameters are set here to perform a database lookup.
However, when we need to look up the same datasource from say a client, the context to lookup is not available by default, and so it needs to be explicitly mentioned.
Hope that explains why some applications contains population of context values and some others dont.
For externalizing the context values(since you may have to change the port number), have the data in an xml file.Read the xml file when the application starts,say into a HashMap, and get the required values from that HashMap.The advantage of such externalization is such you can avoid re-compilation of code and the scope of changes would be limited to xml (config)file.
 
Pooja Agarwal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai All,

Thanks every one and i appreciate each one of u for ur advice.

Actually i was trying to look up in a jdbc program and tried to run it. Came to know that if i try to run this from DOS console as an external program i must specify the properties.

But when tried the same code in a servlet which is deployed in the weblogic server it worked fine.

SO some thing deployed in the weblogic need not specify these properties. If running as an external client code these properties must be specified. Am i right ???

Thanks once again,
I am thankful to each one of u.
Pooja.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic