Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection pool

 
Mathias Nilsson
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers!
I have made a class that implements the ServletContextListener. In this
servlet I make a Connection that I can use in my application. ( I put it in the Context.setAttribute() ).
My problem is that when I use this the Connection will be opened the whole time the application is alive. I want to make a Connection pool soo that I can close the connections after I have used them.
I'm not sure if I have to close them or what's the best approch when coding this. It is just that I've heard of Connection pooling but I don't know how to do it , why it is soo good etc.
I think by using it the way I have coded now that the Connection must finish before it can run a query again. If I have 500 users that want's to connect to the database then I have a big problem.
My question is.
* How do I code a Connection Pool ?
* What is a Connection Pool. ?
I've read that you should use JNDI instead of DriverManager. Is this correct and why?
// Mathias
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most all servlet container/App Servers offer Connection Pooling through jndi. The web site for your app server should have the documentation available. For example, if you are using Tomcat, you can find information here. Once you have that setup you should be good to go. If you have more problems, let us know and we can help.
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
The problem now is that I use jdk1.3 and the javax.sql isn't included.
I have installed jdk1.4 , changed my JAVA_HOME but it is still not available. I'm using Tomcat4. I keep getting error on javax.sql import
// Mathias
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What doesn javax.sql have to do with using Tomcats connection pooling mechanism?
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The samples mysQL , tomcat gave was with that.

The DataSource object is in the javax.sql package
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you display your code AND the error message you are recieving when you compile/run it. Also, if doing this from the command line, include the commands you type to compile/run the program.
Thanks.
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code

Here are the errors

[ November 10, 2003: Message edited by: Mathias Nilsson ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic