tags:

views:

643

answers:

1

I am trying to connect to mysql database using java on windows7. Inspite of adding the complete url of jdbcdriver jar file in CLASSPATH, java.lang.ClassNotFoundException: com.mysql.jdbc.Driver is thrown. Could anyone tell me what i am missing here?? it works if i add the jar file in project library but i want to do it by CLASSPATH itself. My classpath looks like this- C:\jython2.5.1\javalib\mysql-connector-java-5.1.12-bin.jar

I want to make it clear that this is not the actual project i am working on.Actually i am using django with jython which requires jdbc driver to access db. that is the reason why i have to do it using CLASSPATH only.

+2  A: 

The CLASSPATH environment variable is only used by the java.exe command and even then only when used without any of the -cp, -classpath, -jar arguments. It is ignored by IDE's.

That environment variable is in real world also considered a poor practice since it breaks portability. It's only "useful" for Sun to prevent that starters get tired of typing the same classpath again and again in the -cp or -classpath arguments. In real world, batch/shell files are preferred.

In your case you're using an IDE. The classpath is called the "build path" (it represents both compiletime and runtime classpath). You can configure it in the project's properties. You can add a complete folder, you can add individual/external JAR files, you can link projects, etcetera. Make use of it. Forget the whole CLASSPATH environment variable.

BalusC
Thanx for you reply, Actually my project is on django and jython. jython runs on jvm and it needs jdbc drivers to access db. I dnt know of any other way to include a jar file.
Nitin Garg
The detailed answer depends on the runtime environment. At least, you can use `sys.path` environment variable (which is by the way similar to `CLASSPATH` and thus also unportable), or the command argument `-Dpython.path`.
BalusC