aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes problem in getting the database connection from a connection pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "problem in getting the database connection from a connection pool" Watch "problem in getting the database connection from a connection pool" New topic
Author

problem in getting the database connection from a connection pool

Pooja Agarwal
Ranch Hand

Joined: May 19, 2004
Posts: 37
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.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Pooja Agarwal
Ranch Hand

Joined: May 19, 2004
Posts: 37
Looking for some help !!!
Any help is appreciated.

Thanks
Pooja
Ankur Srivastava
Ranch Hand

Joined: May 11, 2004
Posts: 62
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
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Pooja Agarwal
Ranch Hand

Joined: May 19, 2004
Posts: 37
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.
PNS Subramanian
Ranch Hand

Joined: Jul 13, 2004
Posts: 150
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

Joined: May 19, 2004
Posts: 37
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in getting the database connection from a connection pool