Return-Path: X-Original-To: apmail-db-derby-user-archive@www.apache.org Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4F6A58290 for ; Mon, 8 Aug 2011 21:18:44 +0000 (UTC) Received: (qmail 46265 invoked by uid 500); 8 Aug 2011 21:18:43 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 46168 invoked by uid 500); 8 Aug 2011 21:18:43 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 46158 invoked by uid 99); 8 Aug 2011 21:18:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Aug 2011 21:18:43 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of m.v.lunteren@gmail.com designates 209.85.210.45 as permitted sender) Received: from [209.85.210.45] (HELO mail-pz0-f45.google.com) (209.85.210.45) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Aug 2011 21:18:38 +0000 Received: by pzk33 with SMTP id 33so2340785pzk.18 for ; Mon, 08 Aug 2011 14:18:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=+qnFRJ4ZCGPbJuDYa1rwwTInccx/a03v0bgkFZAwGC8=; b=jm9Y5PZ/kjDSHs1qjye34v6ZdU/4FValTmkaGjCltLd9ok6JzLWKXk/dBLM/amYcsn BhA8l8mRgymOXTBEPDYVUTc49uQtfazvo/wLCuziABhIEwyvnBgGeduQa81j6l05mCZA JKE6xwtAP6Rzh9Evvmh0kritXqHceZur5zFvI= MIME-Version: 1.0 Received: by 10.142.213.9 with SMTP id l9mr5745324wfg.233.1312838297971; Mon, 08 Aug 2011 14:18:17 -0700 (PDT) Received: by 10.68.42.136 with HTTP; Mon, 8 Aug 2011 14:18:17 -0700 (PDT) In-Reply-To: <785273626.393012.1312836833756.JavaMail.root@sz0138a.westchester.pa.mail.comcast.net> References: <4E4037D9.7030405@oracle.com> <785273626.393012.1312836833756.JavaMail.root@sz0138a.westchester.pa.mail.comcast.net> Date: Mon, 8 Aug 2011 14:18:17 -0700 Message-ID: Subject: Re: Can't Load Embedded Driver From: Myrna van Lunteren To: Derby Discussion Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Mon, Aug 8, 2011 at 1:53 PM, wrote: > That bottom level plumbing has been working perfectly for two years in de= v. > I remember thinking it was pretty cool and developer-friendly.=A0 I had > essentially NO trouble getting it all up and working.=A0 I have now added= the > code to explicitly load the driver.=A0 It works fine in dev, but not depl= oyed > in a jar (java.lang.ClassNotFoundException: > org.apache.derby.jdbc.EmbeddedDriver).=A0=A0CLASSPATH surely would be the= usual > suspect, but echo %CLASSPATH% yields "C:\Program > Files\Apache\db-derby-10.8.1.2-bin\lib\derby.jar;." (derby.jar really IS = in > that location)=A0and=A0 java org.apache.derby.jdbc.EmbeddedDriver yields > "Exception in thread "main" java.lang.NoSuchMethodError: main" as Rick sa= ys > it should.=A0 So, WTF am I doing wrong?=A0 In Unix, I would have double-c= hecked > rwx permissions (maybe Intellij Idea is running as root), but I'm not as > familiar with this stuff in Windows. > > ________________________________ > From: "Rick Hillegas" > To: "Derby Discussion" > Sent: Monday, August 8, 2011 3:24:09 PM > Subject: Re: Can't Load Embedded Driver > > Hi Roy, > > Thanks for including the code snippet. As Raymond points out, you are > not loading the driver explicitly. This should not be necessary if you > are using Java 6 or 7. However, driver autoloading does not happen in > Java 5 and earlier versions of Java. What version of Java are you using? > > Thanks, > -Rick > > On 8/8/11 11:55 AM, Raymond Kroeker wrote: >> Hi Roy, >> >> The fqcn, is the fully qualified class name of the driver. =A0So in your >> code you're using the driver manager to grab a connection; however I >> don't see a reference to loading the driver: >> >> http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html#embedded_= driver >> >> Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); >> >> Raymond >> >> On Mon, Aug 8, 2011 at 11:47, =A0wrote: >>> I do not know what an "fqcn" is. =A0I am running the latest Derby relea= se, >>> 10.8.1.2. =A0The code pasted in below works great in the dev environmen= t >>> (IntelliJ Idea), but the same code packaged in a jar cannot find the >>> driver >>> with CLASSPATH set correctly. >>> >>> =A0 =A0 public static Connection getConnection() >>> =A0 =A0 { >>> =A0 =A0 =A0 =A0Connection c =3D null; >>> =A0 =A0 =A0 =A0try >>> =A0 =A0 =A0 =A0{ =A0 =A0 =A0 =A0 =A0 =A0 // The connectionURL >>> is "jdbc:derby:EMDatabase;create=3Dtrue" >>> =A0 =A0 =A0 =A0 =A0 c =3D DriverManager.getConnection(connectionURL); >>> =A0 =A0 =A0 =A0 =A0 c.setAutoCommit(false); >>> =A0 =A0 =A0 =A0} >>> =A0 =A0 =A0 =A0catch (Throwable e) >>> =A0 =A0 =A0 =A0{ >>> =A0 =A0 =A0 =A0 =A0 log(3, "Unable to connect to " + dbName + ": =A0" + >>> e.getMessage()); >>> =A0 =A0 =A0 =A0 =A0 stopDBMS(); >>> =A0 =A0 =A0 =A0 =A0 System.exit(3); >>> =A0 =A0 =A0 =A0} >>> =A0 =A0 =A0 =A0return c; >>> =A0 =A0 } >>> >>> >>> >>> ________________________________ >>> >>> From: "Raymond Kroeker" >>> >>> To: "Derby Discussion" >>> Sent: Monday, August 8, 2011 10:08:11 AM >>> Subject: Re: Can't Load Embedded Driver >>> >>> Can you try specifying the driver as a fqcn? If that doesn't solve the >>> issue >>> please paste relevant code around how you load the driver and obtain a >>> connection. >>> >>> Raymond >>> >>> On Aug 8, 2011 6:55 AM, =A0wrote: >>>> >>>> Rick, >>>> >>>> >>>> >>>> Thank you very much for offering your help. =A0Apparently my CLASSPATH= is >>>> good. =A0I typed in "java org.apache.derby.jdbc.EmbeddedDriver" and di= d >>>> indeed >>>> get exactly the expected "Exception in thread "main" >>>> java.lang.NoSuchMethodError: main" error message. =A0What else could b= e >>>> causing =A0my problem? >>>> >>>> >>>> >>>> Roy >>>> >>>> >>>> >>>> >>>> >>>> ----- Original Message ----- >>>> >>>> >>>> From: "Rick Hillegas" >>>> To: "Derby Discussion" >>>> Sent: Monday, August 8, 2011 9:00:58 AM >>>> Subject: Re: Can't Load Embedded Driver >>>> >>>> On 8/7/11 9:54 AM, Roy.Minet@comcast.net wrote: >>>>> I have been happily using Derby for two years within IntelliJ Idea, >>>>> but have now hit a wall trying to deploy the application I developed. >>>>> I have tried setting the path to derby.jar on the command line and/or >>>>> in the CLASSPATH environment variable to no avail. =A0The embedded >>>>> driver doesn't load; the error message is, "No suitable driver found >>>>> for jdbc:derby:EMDatabase;create=3Dtrue". =A0I'm under Windows XP Pro= . >>>>> Any help would be appreciated. >>>>> >>>>> Roy Minet >>>>> >>>>> >>>> Hi Roy, >>>> >>>> This is almost always a CLASSPATH problem. With the same CLASSPATH, tr= y >>>> the following experiment: >>>> >>>> java org.apache.derby.jdbc.EmbeddedDriver >>>> >>>> If the CLASSPATH is good, you should see this error: >>>> >>>> Exception in thread "main" java.lang.NoSuchMethodError: main >>>> >>>> Hope this helps, >>>> -Rick >> >> > Looks like it should work. Perhaps derby/intelliJ Idea/the jvm has trouble with the space in the classpath. I think with some tools I have to use the 8 character DOS equivalent (e.g. Progra~1 instead of Program Files) when I refer to directory names with spaces. So, perhaps it's worth a quick try to see if it works if you plop derby.jar and/or your other jar somewhere else than in the Program Files directory (and adjust the classpath too, of course). Myrna