You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Bogdan Mihaila <bo...@ctce.ro> on 2005/08/08 12:46:05 UTC

derby jdbc load driver

Hello!

I'm trying to load the embedded derby driver, like this:

Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();

It throws an exception, saying it cannot load the driver.
I've put the derby jars in classpath (I work in Eclipse)

What is wrong? Please help me
Bogdan

Re: derby jdbc load driver

Posted by Rajesh Kartha <ka...@Source-Zone.Org>.
Hello,

Since you are using the Embedded Driver, can you please check the 
CLASSPATH (i.e  Java Build Path -> Libraries under the
project Properties), if it has the 'derby.jar'.

I just tried it under Eclipse and it works for me.

public static void main(String[] args) {
        try{
            
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
            System.out.println("Driver Loaded");
        }catch(Exception e){
            System.out.println("Error "+e);
        }

    }
Output:
Driver Loaded

Regards,
Rajesh

Bogdan Mihaila wrote:

> Hello!
>  
> I'm trying to load the embedded derby driver, like this:
>  
> Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
>  
> It throws an exception, saying it cannot load the driver.
> I've put the derby jars in classpath (I work in Eclipse)
>  
> What is wrong? Please help me
> Bogdan




Re: derby jdbc load driver

Posted by Jeremy Boynes <jb...@apache.org>.
Oyvind.Bakksjo@Sun.COM wrote:
> 
> What instance? Since there is no .newInstance() here, this can be 
> understood as if the class has a static initializer which creates an 
> instance of the class. And if so, why should the application do 
> .newInstance()?
> 

 From memory, some drivers do not register in a static initializer but 
in the constructor. I don't believe this is compliant behaviour but if 
you want something to work ...

Many applications will be choosing the Driver dynamically so something like:

    Class.forName(System.getProperty("driver")).newInstance()

is most likely to work.
--
Jeremy

Re: derby jdbc load driver

Posted by Oy...@Sun.COM.
Satheesh Bandaram wrote:
> Agreed... Guess we should document this correctly. Shall I file a
> document bug or would you want to?
> 
> Satheesh

I have created a JIRA issue for it.

http://issues.apache.org/jira/browse/DERBY-503

-- 
Øyvind Bakksjø
Sun Microsystems, Database Technology Group
Haakon VII gt. 7b, N-7485 Trondheim, Norway
Tel: x43419 / +47 73842119, Fax: +47 73842101

Re: derby jdbc load driver

Posted by Satheesh Bandaram <sa...@Sourcery.Org>.
Agreed... Guess we should document this correctly. Shall I file a
document bug or would you want to?

Satheesh

Oyvind.Bakksjo@Sun.COM wrote:

> Satheesh Bandaram wrote:
>
>> I think Derby recommends using *.newInstance()* to load JDBC
>> drivers... In fact, it is required if you plan to shutdown and reboot
>> databases on the same thread/VM for Derby. Take a look at the javadoc
>> for EmbeddedDriver.
>
>
> Ok. But if Derby recommends it, then it should be explicitly mentioned
> in the manuals (both in the Reference and the Developer's Guide),
> which it isn't:
>
> http://db.apache.org/derby/docs/10.1/devguide/cdevdvlp40653.html
> http://db.apache.org/derby/docs/10.1/ref/rrefjdbc32052.html
>
> Instead, there are contradicting statements like the one below:
>
> ---------------
> * Class.forName("org.apache.derby.jdbc.EmbeddedDriver")
>
> Our recommended manner, because it ensures that the class is loaded in
> all JVMs by creating an instance at the same time.
> ---------------
>
> What instance? Since there is no .newInstance() here, this can be
> understood as if the class has a static initializer which creates an
> instance of the class. And if so, why should the application do
> .newInstance()?
>


Re: derby jdbc load driver

Posted by Amit Handa <Am...@Sun.COM>.
fyi,
We are moving away from the approach of doing a Class.forName() in apps 
from JDBC 4.0 onwards
if you package your driver as a service(according to Jar Spec).

You can go through the Spec Early Draft Review available at 
http://jcp.org/en/jsr/detail?id=221

thanks,
Amit


Oyvind.Bakksjo@Sun.COM wrote:

> Satheesh Bandaram wrote:
>
>> I think Derby recommends using *.newInstance()* to load JDBC 
>> drivers... In fact, it is required if you plan to shutdown and reboot 
>> databases on the same thread/VM for Derby. Take a look at the javadoc 
>> for EmbeddedDriver.
>
>
> Ok. But if Derby recommends it, then it should be explicitly mentioned 
> in the manuals (both in the Reference and the Developer's Guide), 
> which it isn't:
>
> http://db.apache.org/derby/docs/10.1/devguide/cdevdvlp40653.html
> http://db.apache.org/derby/docs/10.1/ref/rrefjdbc32052.html
>
> Instead, there are contradicting statements like the one below:
>
> ---------------
> * Class.forName("org.apache.derby.jdbc.EmbeddedDriver")
>
> Our recommended manner, because it ensures that the class is loaded in 
> all JVMs by creating an instance at the same time.
> ---------------
>
> What instance? Since there is no .newInstance() here, this can be 
> understood as if the class has a static initializer which creates an 
> instance of the class. And if so, why should the application do 
> .newInstance()?
>


Re: derby jdbc load driver

Posted by Oy...@Sun.COM.
Satheesh Bandaram wrote:
> I think Derby recommends using *.newInstance()* to load JDBC drivers... 
> In fact, it is required if you plan to shutdown and reboot databases on 
> the same thread/VM for Derby. Take a look at the javadoc for EmbeddedDriver.

Ok. But if Derby recommends it, then it should be explicitly mentioned 
in the manuals (both in the Reference and the Developer's Guide), which 
it isn't:

http://db.apache.org/derby/docs/10.1/devguide/cdevdvlp40653.html
http://db.apache.org/derby/docs/10.1/ref/rrefjdbc32052.html

Instead, there are contradicting statements like the one below:

---------------
* Class.forName("org.apache.derby.jdbc.EmbeddedDriver")

Our recommended manner, because it ensures that the class is loaded in 
all JVMs by creating an instance at the same time.
---------------

What instance? Since there is no .newInstance() here, this can be 
understood as if the class has a static initializer which creates an 
instance of the class. And if so, why should the application do 
.newInstance()?

-- 
Øyvind Bakksjø
Sun Microsystems, Web Services, Database Technology Group
Haakon VII gt. 7b, N-7485 Trondheim, Norway
Tel: x43419 / +47 73842119, Fax: +47 73842101

Re: derby jdbc load driver

Posted by Oy...@Sun.COM.
Bogdan Mihaila wrote:
> Hello!
>  
> I'm trying to load the embedded derby driver, like this:
>  
> Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();

As Rajesh pointed out, the problem is most likely the CLASSPATH. If you 
still have problems, please send the complete exception, including stack 
trace, as this helps to figure out the problem.

By the way, you don't need the '.newInstance()' part - simply loading 
the driver class will set up the Derby system.

-- 
Øyvind Bakksjø
Sun Microsystems, Web Services, Database Technology Group
Haakon VII gt. 7b, N-7485 Trondheim, Norway
Tel: x43419 / +47 73842119, Fax: +47 73842101