This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Derby connection problem...

 
james hagbard
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I am working on a project for a class I am taking and I am having a problem with making the JDBC connection to my JavaDB aka Derby database.

At run time I am getting
could not connect
java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
<snipped for brevity>
at excelfileparser.DB.dbConnect(DB.java:23)
at excelfileparser.Main.main(Main.java:22)


From my reading, searching and pulling my hair out, it seems that its a classpath issue.

I am using ubuntu 9.04 (Jaunty) and Netbeans

Here are the relevent lines from my .bashrc

export PATH=$PATH:/usr/share/javadb/bin/
export DERBY_HOME=/usr/share/javadb
CLASSPATH=.:/home/james/SUNWappserver/javadb/lib
export CLASSPATH

I found the derbyclient.jar in two places
/home/james/sges-v3-prelude/javadb/lib

and

/home/james/SUNWappserver/javadb/lib

In netbeans I can make the connection to the database without any issue by using the gui tool, however, we are learning how to do this 'manually' and the boilerplate code generated by Netbeans doesn't really make this connection obvious.

Any help would be appreciated!

-James
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CLASSPATH=.:/home/james/SUNWappserver/javadb/lib

I generally advise not to use the CLASSPATH environment setting, but to use an explicit "-classpath" switch on the command line - I find it easier to use, although that's more of a personal preference than a hard and fast rule.

The problem here is that "/home/james/SUNWappserver/javadb/lib" is a directory, and you seem to assume that jar files inside of directories will be added to the classpath. But that's not the case - you need to add the individual jar files to the classpath. Something like "CLASSPATH=.:/home/james/SUNWappserver/javadb/lib/derbyclient.jar" may do the trick.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49396
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there is a better reason than "personal preference" against using a system CLASSPATH. Each application will require a different CLASSPATH entry, so the environment variable will rapidly become cluttered, and difficult to maintain. Deleting or editing part of the CLASSPATH may cause other applications to fail. If each application maintains its own CLASSPATH maintenance is much easier.
 
james hagbard
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this one figured out actually.

It was simply a setting I needed to make in NetBeans.
I feel silly...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic