| Author |
Connection pool
|
Mathias Nilsson
Ranch Hand
Joined: Oct 13, 2003
Posts: 107
|
|
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
|
SCJP2 , MCP( 70-229 ) , Preparing For SCWDC
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
|
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
Joined: Oct 13, 2003
Posts: 107
|
|
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
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
|
What doesn javax.sql have to do with using Tomcats connection pooling mechanism?
|
 |
Mathias Nilsson
Ranch Hand
Joined: Oct 13, 2003
Posts: 107
|
|
The samples mysQL , tomcat gave was with that. The DataSource object is in the javax.sql package
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
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
Joined: Oct 13, 2003
Posts: 107
|
|
Here is the code Here are the errors [ November 10, 2003: Message edited by: Mathias Nilsson ]
|
 |
 |
|
|
subject: Connection pool
|
|
|