set classpath enviroment variable for Connector/J

Do I need to set classpath enviroment variable for Connector/J?I use NetBeans IDE 5.5.
[100 byte] By [ardmorea] at [2007-11-26 21:54:34]
# 1
You never need to set the env variable.If you want to use a JDBC driver that driver must be in you class path (which is not the same as the env variable.) There are a number of ways that the driver can get into your class path.
jschella at 2007-7-10 3:49:32 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Classpath is set as:

C:\Program Files\Java\jdk1.6.0\bin;C:\Program Files\Java\jdk1.6.0\lib;C:\Program Files\Java\jdk1.6.0\lib\tools.jar;.;C:\Program Files\Java\jdk1.6.0\lib\dt.jar;C:\MySQL\Connector-Java\debug\mysql-connector-java-5.0.5-bin-g.jar

BUT

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

ardmorea at 2007-7-10 3:49:32 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

> Classpath is set as:

How do you know?

You can always verify a class path.

1. Open a console window.

2. Run the following command.

java -cp <something> <MyClass>

If it does not find MyClass it will return a class not found exception. In that case there is always something wrong with the class path.

You might note that at least in the past the Sun VM just stopped looking if there were absolutely any errors at all in the class path. So for example if there is any problem at all with dt.jar (in your posted path) then it will never get to the last jar.

jschella at 2007-7-10 3:49:33 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
yes. it is true.C:\Documents and Settings\Owner>java -cp client MyclassException in thread "main" java.lang.NoClassDefFoundError: MyclassSo how can I fix it?Thanks
ardmorea at 2007-7-10 3:49:33 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

I was suggesting a simple method to determine if the class path you have by itself provides the jdbc driver.

That simple method allows you to diagnose class path problems outside of code.

What you want to type is the class path that you already provided (the one with dt.jar) and the class that you are already missing(com.mysql.jdbc.Driver)

And you did not specify how you determined what the class path was.

jschella at 2007-7-10 3:49:33 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
Can I set CLASSPATH=path1;path2 ...thenpath1=...;path2=...;
ardmorea at 2007-7-10 3:49:33 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
One more question isthere were absolutely any errors at all in the class path.It seems everything is right in the class path, so what is wrong?
ardmorea at 2007-7-10 3:49:33 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8

> It seems everything is right in the class path, so

> what is wrong?

I posted a method for you to determine exactly (not guessing) if there are problems or not.

1. Please post the exact command that you used based on the method that I presented and the exact output you got based on running that command.

2. You posted a class path above. Please post the exact way that you determined what that class path was. (I do NOT want to know how you created it - I want to know how you know that the above is the class path you are using.)

jschella at 2007-7-10 3:49:33 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9
>You might note that at least in the past the Sun VM just stopped looking if there were absolutely any errors at all in the class path.So it means that once jvm encounter the first .jar in classpath it will ignore the other .jar because ther are considered as lower priority?
ardmorea at 2007-7-10 3:49:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 10

> >You might note that at least in the past the Sun VM

> just stopped looking if there were absolutely any

> errors at all in the class path.

>

> So it means that once jvm encounter the first .jar in

> classpath it will ignore the other .jar because ther

> are considered as lower priority?

Error means error. Finding a jar is not an error. Not finding a jar is an error.

jschella at 2007-7-10 3:49:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...