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.
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.
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.
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.
Joined: May 19, 2004
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.
subject: problem in getting the database connection from a connection pool