|
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
|
