Hi. Here's my situation. I'm using DBConnectionBroker (www.javaexchange.com) as connection pooling for my web application. You initialize the broker with, say, 10 connections and everytime you need to perform database actions you getConnection, use it and then freeConnection. Simple. The initialization of this broker variable takes place in the firstservlet that hits the application. So what I do is initialize the broker and put this variable in the context so I can use it throughout my web application. And it is working fine. but... it is working fine but only if you call the index page at the very beginning. http://www.mysite.com. if I type this a servlet (my InitController servlet) will initialize my broker, put this variable in the broker and it is ready to be used. BUT, if I type something like this at the very beginning: http://www.mysite.com/aboutUs.jsp if aboutUs.jsp needs connection to the database, it throws a null pointer exception because my broker has never been initialized. So, what's the solution for this problem? Is someone here that is using javaexchange as connection pooling? thankssss
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
I do not know what kind of application you have. But if the application needs some login, usually its better to initialise and put the connection pool in context during the login. Otherwise if you are using an MVC architucture /Struts what you can do is, before calling any presentation (jsp) call an action class that initialises the connection pool, if already not. So every time a query is fired it will always find the connection .I think this is most simple and elegent solution. Kaustubh.
Kaustubh. Mumbai, India.
Joined: Nov 27, 2001
Hi, thnx for your response.
Originally posted by kaustubh patil: I do not know what kind of application you have. But if the application needs some login, usually its better to initialise and put the connection pool in context during the login.
It doesn't need login.
Otherwise if you are using an MVC architucture /Struts what you can do is, before calling any presentation (jsp) call an action class that initialises the connection pool, if already not......
So, if I have www.mysite.com/aboutUs.jsp and this page requires database connection, How do I call this action class before reaching aboutUs.jsp?? thanks
Hi, If you need something to be initialised when the web application starts then you should do the following: 1) Place the code to be run at startup in the init() method of the servlet. 2) In the deployment descriptor (web.xml) set the servlet to load-at-startup and the init() method will be run before the container accepts any client requests. Take a look at the Servlet Specification for further information on load-at-startup and the servlet life cycle Cheers, Steve
Joined: Nov 27, 2001
thank you guys. <load-on-startup> was what I needed.
Are you using the Servlet 2.3 API? If so, you can use a ServletContextListener to initialize your connection pool. Override the contextInitialized() method and do the initialization there. This is the new way (the old way was to force servlet initialization via a load-on-startup tag) to initialize your application.
James Carman, President<br />Carman Consulting, Inc.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com