Hi,
 
the code is nearly identical, no matter if you use a servlet or a standalone app. The point is, that you need one and only one place in your application where you initialize the connection broker. There is more than one way to achieve this. The following code uses a class with some static methods that delegate getConnection() and freeConnection() to an Instance of DbConnectionBroker:
 
 
 
import com.javaexchange.dbConnectionBroker.DbConnectionBroker;
 
import java.io.IOException;
import java.sql.Connection;
 

public class Broker {
 
    private static DbConnectionBroker connBroker;
 
    static {
        try {
            connBroker = new DbConnectionBroker("com.sap.dbtech.jdbc.DriverSapDB", "jdbc:sapdb://host/databasename", "user", "password", 2, 6, "D:\\logs\\log", 1.0);
        } catch (IOException ex) {
            throw new RuntimeException(ex.getMessage());
        }
    }

    public static Connection getConnection() {
        return connBroker.getConnection();
    }
 
    public static void freeConnection(Connection conn) {
        connBroker.freeConnection(conn);
    }

}
 
 
 
You get a connection by calling
 
Connection conn = Broker.getConnection();
 
somewhere in your application.
 
After you are done with the Connection you ***MUST*** free it. (Never ever forget to do that!) :
 
Broker.freeConnection(conn);
 
 
Remember that you have to adjust the URL and the location of the logfiles in the code above to match your environment.
 
 
hope this helps,
Detlef

 
 
 
 
 
----- Original Message -----
Sent: Tuesday, May 27, 2003 11:42 PM
Subject: Re: JDBC Connection Pooling again

Detlef:
 
Sorry for the confusion. Let me rephrase what I want to do. I am creating a 2-tier client-server application without any application server. But I want a connection pool (a java class) of say 50 connections on the server where my database is running, so as to speed up client connections. What should be my architecture and how do I design it using Java and SAP-DB? Yeah, I am talking of the DBConnectionBroker on javaexchange. But that example too shows servlet implementation.
 
Thanks,
Vanita
 

Reply via email to