3 messages in com.mysql.lists.javaRE: Initialize a db connection for al...
FromSent OnAttachments
Vincent Stoessel14 Nov 2000 13:49 
adi...@earthling.net14 Nov 2000 20:28 
Stephan Gruschke15 Nov 2000 02:50 
Subject:RE: Initialize a db connection for all servlets in a zone
From:adi...@earthling.net (adi@earthling.net)
Date:11/14/2000 08:28:55 PM
List:com.mysql.lists.java

You can accomplish this by using a child-parent relationship - nothing to do
with servlets.

public abstract class JDBCAccess { protected Connection getConnection() { // creates connection and returns it. the only place where the creating code
resides. // This could be a broker returning a connection too. }

protected void freeConnection(Connection ) { // basically frees connection. // This could be releasing the connection to the broker. } }

public class JDBCUserAccess extends JDBCAccess implements IUserAccess { private Connection mConn; public User getUser(int userId) { try { mConn = getConnection(); } catch (SQLException e) { } finally { if (mConn != null) { freeConnection(mConn); // this is important } } }

In your servlets, IUserAccess userAccess = new JDBCUserAccess(); User user = userAccess.getUser(4);

try using the com.javaexchange.dbConnectionBroker.* broker classes...

regards kini

-----Original Message----- From: Vincent Stoessel [mailto:vin@idev.com] Sent: Wednesday, November 15, 2000 3:20 AM To: ja@lists.mysql.com Subject: Initialize a db connection for all servlets in a zone

Hello, Question for you servlet programmers out there. is there a way to initialize a connection to mysql as my servlets startup? I'm basically sick of typing the following on all my db connecting pages.

Class.forName("org.gjt.mm.mysql.Driver").newInstance(); con = DriverManager.getConnection("usual stuff in here");

using mysql 3.23.x ApacheJserv 1.1.2 mm jdbc 2.0.2 driver

i would love to have one place to set the connection.

P.S. don't talk about data base pools unless you have a REAL easy example.

Thanks in advance.

-- Vincent Stoessel vin@idev.com Internet Applications Engineer IDEV http://www.idev.com V: 301 495 7345 x129

--------------------------------------------------------------------- Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before posting. To request this thread, e-mail java@lists.mysql.com

To unsubscribe, send a message to the address shown in the List-Unsubscribe header of this message. If you cannot see it, e-mail java@lists.mysql.com instead.

--------------------------------------------------- Get free personalized email at http://www.iname.com