Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 61005 invoked from network); 30 May 2006 11:35:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 30 May 2006 11:35:05 -0000 Received: (qmail 99407 invoked by uid 500); 30 May 2006 11:35:04 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 99371 invoked by uid 500); 30 May 2006 11:35:04 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 99362 invoked by uid 99); 30 May 2006 11:35:04 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 May 2006 04:35:04 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [192.18.1.36] (HELO gmpea-pix-1.sun.com) (192.18.1.36) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 May 2006 04:35:03 -0700 Received: from d1-emea-09.sun.com ([192.18.2.119]) by gmpea-pix-1.sun.com (8.12.9/8.12.9) with ESMTP id k4UBYf4x007683 for ; Tue, 30 May 2006 12:34:42 +0100 (BST) Received: from conversion-daemon.d1-emea-09.sun.com by d1-emea-09.sun.com (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) id <0J0200M01TCWES00@d1-emea-09.sun.com> (original mail from Knut.Hatlen@Sun.COM) for derby-dev@db.apache.org; Tue, 30 May 2006 12:34:41 +0100 (BST) Received: from khepri19 ([129.159.112.231]) by d1-emea-09.sun.com (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPSA id <0J02005UOTHSNIA0@d1-emea-09.sun.com> for derby-dev@db.apache.org; Tue, 30 May 2006 12:34:41 +0100 (BST) Date: Tue, 30 May 2006 13:34:40 +0200 From: Knut Anders Hatlen Subject: Re: Autoloading of JDBC drivers considered harmful? In-reply-to: <447C25A4.8090708@sun.com> Sender: Knut.Hatlen@Sun.COM To: derby-dev@db.apache.org Message-id: Organization: Sun Microsystems MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT References: <44778871.4030006@sun.com> <447B02B5.6080600@sun.com> <447C25A4.8090708@sun.com> User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.0.50 (usg-unix-v) X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Olav Sandstaa writes: > To confirm that this was not something special triggered by the DB2 > driver, I ran the same test program loading the Derby Network client, > MySQL and PostgreSQL JDBC drivers. With derby.jar in the class path > the embedded driver and engine are loaded in all cases. It sounds like the problem is that the loading of the embedded JDBC driver includes starting and initializing the engine. Other (non-embedded) databases don't have this problem because loading the driver simply registers it with the DriverManager. Perhaps we could solve the problem by separating registration of the driver and startup of the engine? That is, Class.forName("EmbeddedDriver") only registers the driver, but no reading of system properties or starting of service threads happens until getConnection() is called. Another issue with Derby and autoloading is that it only happens once per JVM. If you do a getConnection("jdbc:derby:;shutdown=true"), the driver is unloaded and won't be reloaded unless you do a Class.forName(). So this code Connection c = DriverManager.getConnection("jdbc:derby:mydb"); doSomethingWithConnection(c); try { DriverManager.getConnection("jdbc:derby:;shutdown=true"); } catch (SQLException) { /* shutdown exception */ } runs fine the first time it is executed, but if it is executed later within the same JVM, it fails with "no suitable driver". I admit this is a special case, but at least it shows that you cannot go through your code and remove all calls to Class.forName(driver) and expect the autoloading to work automagically with Derby today. -- Knut Anders