import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.javaexchange.dbConnectionBroker.*;

/* This example shows how to set up Global
   Database Connection Broker. 

   For example, if you had 40 servlets and a 5 user license for your database,
   you might want to set up a global broker with a max pool size of 5.  That
   way, all 40 servlets would share the 5 connections in Round-Robin order.

   All the work of setting up the global connection pool is done in the 
   superclass HttpServletJXGB

   - Marc A. Mnich
public class GlobalBrokerExample1 extends HttpServletJXGB {

    Connection conn = null;

    public void doGet (HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException

	ServletOutputStream out = res.getOutputStream();

	out.println("JDBCGlobalBroker Example 1:");

      // The global pool object myBroker is set up in the superclass!	
      conn = myBroker.getConnection();  
      Statement stmt=null;

      try {

          // Create a Statement.  
          stmt = conn.createStatement ();  

          // Set up the Result Set 
          ResultSet rset = stmt.executeQuery ("select sysdate from dual");

          // Print out the results
          while ( ())
            out.println ("The query responded with: " + rset.getString(1));
        catch (SQLException e2) {
            out.println("SQL exception.");
        finally {
            try{if(stmt != null) {stmt.close();}} catch(SQLException e1){};

            myBroker.freeConnection(conn);  // Release connection back to pool