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 Timothy Allen <Ti...@uk.ibm.com> on 2010/11/09 16:38:58 UTC

I cannot link to Derby from a java program in ECLIPSE, and I cannot find out why

Hello,

I wonder if you can help me.

1/
I link to Derby using an embedded driver using Eclipse using database 
connections, I can see the data in the databases

2/
I link to Derby using the ij tool


3/
I simply cannot get my java program to read a db at all

I have tried both of  the commands below.



//private static String dbURL = "jdbc:derby://localhost
:1527/myDB;create=true;user=me;password=mine";
   private static String dbURL = "jdbc:derby:myDB;create=true;"
;



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


The only result I get is below. Please, what is wrong ? This seems 
impossible to solve!

Thanks


java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at myapp.Restaurants.createConnection(Restaurants.java:34)
        at myapp.Restaurants.main(Restaurants.java:23)
Exception in thread "main" java.lang.NullPointerException
        at myapp.Restaurants.insertRestaurants(Restaurants.java:51)
        at myapp.Restaurants.main(Restaurants.java:24)



Timothy Allen, Accelerated Value Leader
World Wide IBM Software Accelerated Value Program
Phone: + 44 (0)2088 443191
Internal Phone: 363191
Mobile:0787 2816836
Timothy_Allen@uk.ibm.com
Visit IBM Software Accelerated Value Online

    


 





Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 
741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU






Re: I cannot link to Derby from a java program in ECLIPSE, and I cannot find out why

Posted by Charlie Kelly <Ch...@CharlieKelly.com>.
Hi TImothy,

How are you linking the derby jar file in Eclipse?

Charlie

On 11/9/2010 7:38 AM, Timothy Allen wrote:
>
> Hello,
>
> I wonder if you can help me.
>
> 1/
> I link to Derby using an embedded driver using Eclipse using database 
> connections, I can see the data in the databases
>
> 2/
> I link to Derby using the ij tool
>
>
> 3/
> I simply cannot get my java program to read a db at all
>
> I have tried both of  the commands below.
>
>
>
> //private static String dbURL = 
> "jdbc:derby://_localhost_:1527/myDB;create=true;user=me;password=mine";
> *private**static*String /dbURL/= "jdbc:derby:myDB;create=true;"
> ;
>
>
>
> //Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
>             
> Class./forName/("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
>
>
> The only result I get is below. Please, what is wrong ? This seems 
> impossible to solve!
>
> Thanks
>
>
> _java.lang.ClassNotFoundException_: org.apache.derby.jdbc.EmbeddedDriver
>         at java.net.URLClassLoader$1.run(Unknown Source)
>         at java.security.AccessController.doPrivileged(_Native Method_)
>         at java.net.URLClassLoader.findClass(Unknown Source)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at java.lang.Class.forName0(_Native Method_)
>         at java.lang.Class.forName(Unknown Source)
>         at myapp.Restaurants.createConnection(_Restaurants.java:34_)
>         at myapp.Restaurants.main(_Restaurants.java:23_)
> Exception in thread "main" _java.lang.NullPointerException_
>         at myapp.Restaurants.insertRestaurants(_Restaurants.java:51_)
>         at myapp.Restaurants.main(_Restaurants.java:24_)
> 	*Timothy Allen, Accelerated Value Leader*
> World Wide IBM Software Accelerated Value Program
> Phone: + 44 (0)2088 443191
> Internal Phone: 363191
> Mobile:0787 2816836_
> __Timothy_Allen@uk.ibm.com_ <ma...@uk.ibm.com>_
> __Visit IBM Software Accelerated Value Online_ 
> <http://www.ibm.com/software/support/acceleratedvalue/>
> _
> _<http://www.linkedin.com/groups?gid=1650807><https://twitter.com/IBMSoftwareValu><http://www.ibm.com/developerworks/spaces/SoftwareAcceleratedValue> 
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> /
> /
>
> /Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales with 
> number 741598.
> Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 
> 3AU/
>
>
>
>
>
>


Re: I cannot link to Derby from a java program in ECLIPSE, and I cannot find out why

Posted by Trevor Carpenter <tr...@ed.ac.uk>.
Hi Timothy

Reading your email (possibly incorrectly?) but it seems that you only  
have difficulty when you execute the program?

it may be to do with the classpath and the JVM not being able to find  
the required jars?

see here for more info on the class path (esp. the gotchas section):
http://mindprod.com/jgloss/classpath.html

I am not an eclipse user but other IDEs allow control over the class  
path and packaged libs etc.

Hope that helps

Trevor

Quoting Timothy Allen <Ti...@uk.ibm.com>:

> Hello,
>
> I wonder if you can help me.
>
> 1/
> I link to Derby using an embedded driver using Eclipse using database
> connections, I can see the data in the databases
>
> 2/
> I link to Derby using the ij tool
>
>
> 3/
> I simply cannot get my java program to read a db at all
>
> I have tried both of  the commands below.
>
>
>
> //private static String dbURL = "jdbc:derby://localhost
> :1527/myDB;create=true;user=me;password=mine";
>    private static String dbURL = "jdbc:derby:myDB;create=true;"
> ;
>
>
>
> //Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
>             Class.forName("org.apache.derby.jdbc.EmbeddedDriver"
> ).newInstance();
>
>
> The only result I get is below. Please, what is wrong ? This seems
> impossible to solve!
>
> Thanks
>
>
> java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
>         at java.net.URLClassLoader$1.run(Unknown Source)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(Unknown Source)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at java.lang.Class.forName0(Native Method)
>         at java.lang.Class.forName(Unknown Source)
>         at myapp.Restaurants.createConnection(Restaurants.java:34)
>         at myapp.Restaurants.main(Restaurants.java:23)
> Exception in thread "main" java.lang.NullPointerException
>         at myapp.Restaurants.insertRestaurants(Restaurants.java:51)
>         at myapp.Restaurants.main(Restaurants.java:24)
>
>
>
> Timothy Allen, Accelerated Value Leader
> World Wide IBM Software Accelerated Value Program
> Phone: + 44 (0)2088 443191
> Internal Phone: 363191
> Mobile:0787 2816836
> Timothy_Allen@uk.ibm.com
> Visit IBM Software Accelerated Value Online
>
>
>
>
>
>
>
>
>
>
> Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales with number
> 741598.
> Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
>
>
>
>
>
>



-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.