• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Connection pool

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What doesn javax.sql have to do with using Tomcats connection pooling mechanism?
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The samples mysQL , tomcat gave was with that.

The DataSource object is in the javax.sql package
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the code

Here are the errors

[ November 10, 2003: Message edited by: Mathias Nilsson ]
 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic