Hello everybody.. First of all, I'm sorry if this wasn't the place to post such topic, but honestly I didn't find the place to post it in, so feel free moving it please. My problem is that I have a fully working system using Servlets + JSF + JSP + JDBC. I deployed my project as .war file and running it through TomCat container on our server, it works fine for about two days or one day, then it stops, and gives NullPointerException whenever you request anything from it. and for my surprise it just works fine after a restart. I changed the server and the container to glassfish, but also having the same after two days, and again i restart the container and it works.. you know am doubting that the connection with db is stopping or something, because I create the connection using ServletContextListener at the loading of my application, so maybe it's getting idol or something.. !! I don't know.. kindly inform me with some solutions for this.. thanks in advance for your help..
Thanks for reply, Will honestly I learnt this way of creating the connection and closing it from a respected book, but as you said the attribute is being removed before closing it, and that's what leading to NullPointerException.
I'm not sure why you want to keep your connection open for 2 days, why not return it to a connection pool? How many concurrent users do you have that use this one connection?
will I have about 350 to 400 people using this System so they might be using it at the same time, or differently (no one knows), so I need to keep this connection always (as I think, for now..) but can you please explain me what do you exactly mean by "return it to a connection pool", honestly don't know it..like is it another way for creating and destroying the connection ??.. your help is really appreciated ,, thanks..
Joined: Jul 17, 2006
One connection will give problems if one user just did an update (but has not yet committed), and another user wants to rollback because of an exception. This will also rollback the update of the first user (if you use only one connection).
It's better to give each request a connection to the database (if needed), and to close the connection as soon as possible. Because getting a connection takes some time, it's better to get a connection from a connection pool. The connection pool has some real connections to the database, the application gets connections from the pool.
There's basically 2 ways: -the application maintains it's own pool (see http://commons.apache.org/dbcp/) -the application uses a connection pool from the server (that's the best way)