import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; import com.javaexchange.dbConnectionBroker.*; /* This example has been adapted from the GlobalBrokerExample1.java file available from www.javaexchange.com. It has been modified to work specifically with MySQL and Servlets.Net web hosting services. The example shows how to set up a global Database Connection Broker in a Servlet using JDBCGlobalBroker and DbConnectionBroker. Once a JDBCGlobalBroker has been created, the settings that it was created with will be used for all additional instances of the class. This allows all of your servlets to use the same pool of database connections. For example, if you had 10 servlets and a 2 database connections to your database, you will want to set up a global broker with a max pool size of 2. That way, all 10 servlets would share the 2 connections in round-robin order. You could alternatively have each servlet manage its own pool of database connections. This can be done by creating an instance of JDBCConnectionBroker rather than JDBCGlobalBroker. The drawback is that each servlet will then need its own set of database connections, potentially using more connections than your Servlets.Net account allows. Servlets.Net encourages you to use the JDBCGlobablBroker and share a pool of all of your connections with all of your servlets. This sample demonstrates how to do this. Whenever you change a servlet or a JSP page on your site, Live Software's JRun servlet runner will reload all of your servlets. When this happens, your broker will be destroyed and a new one created. This might cause problems. To avoid this, you should set up a "master broker servlet" that extends the PermanentServlet class: com.livesoftware.jrun.PermanentServlet Servlets implementing this interface will have their "init" and "destroy" methods called when first loaded, and when the servlet engine shuts down. Usually, these type of servlets should not be dynamically reloaded. This means that these servlets should be placed within your "classes" directory rather than within your "servlets" directory. - Servlets.Net Support Staff */ public class MySQLBrokerExample extends HttpServlet { Connection conn = null; JDBCGlobalBroker myGlobalBroker; // A global (all Servlets) connection pool public void destroy() { super.destroy(); myGlobalBroker.destroy(); } public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); ServletOutputStream out = res.getOutputStream(); out.println(""); out.println("