• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connector/J driver error

 
Keith Wegner
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hate to ask such a simple question on this board, but I'm not seeing this one...

I'm running 64-bit Vista
Eclipse Version 3.4.1, installed to C:\Program Files (x86)\eclipse
Java JDK is installed to C:\jdk1.6.0_12
Connector/J is installed to C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8

CLASSPATH=.;C:\apache-tomcat-5.5.17\common\lib\servlet-api.jar;C:\apache-tomcat-5.5.17\common\lib\jsp-api.jar;C:\Servlets+JSP;..;..\..;C:\apache-tomcat-5.5.27\apache-tomcat-5.5.27\common\lib\servlet-api.jar;C:\apache-tomcat-5.5.27\apache-tomcat-5.5.27\common\lib\jsp-api.jar;C:\Users\kwegner83\Servlets+JSP;C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8-bin.jar;C:\Users\kwegner83\workspace\

JAVA_HOME=C:\jdk1.6.0_12

Trying to run the following code displays Driver not loaded => java.lang.ClassNotFoundException: com.mysql.jdbc.Driver to the console:

import java.sql.*;
public class DBTest {
public static void main(String[] args)
{
try
{ Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e)
{
System.out.println("Driver not loaded => " + e);
System.exit(1);
}
}
}

What's going on here?
 
Jan Cumps
Bartender
Posts: 2584
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add the Connector/J jar to your project classpath in Eclipse.
 
Dhruva Mistry
Ranch Hand
Posts: 67
Eclipse IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya.....and it should be in the <project name> folder like all supporting jar files resides
 
Hector Tenedero
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add the Connector / J to the project's build path. It's usually found in the Project menu ( alt+p )
 
Jan Cumps
Bartender
Posts: 2584
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dhruva mistry wrote:ya.....and it should be in the &lt;project name&gt; folder like all supporting jar files resides
No.
 
Keith Wegner
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jan Cumps wrote:Add the Connector/J jar to your project classpath in Eclipse.


It is in the CLASSPATH already:

C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8-bin.jar;

<EDIT> Actually, I'm not sure how to add it to the project classpath. Can you explain?</EDIT>
 
Jan Cumps
Bartender
Posts: 2584
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eclipse does not use your classpath when compiling / running your project.

from https://eclipse-tutorial.dev.java.net/eclipse-tutorial/part1.html

Right-click on the project and select "Properties". Go to the "Libraries" tab in "Java Build Path":
Click on "Add (external) JARs..." ...
 
Keith Wegner
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jan Cumps wrote:Eclipse does not use your classpath when compiling / running your project.

from https://eclipse-tutorial.dev.java.net/eclipse-tutorial/part1.html

Right-click on the project and select "Properties". Go to the "Libraries" tab in "Java Build Path":
Click on "Add (external) JARs..." ...


I should have also mentioned that I tried adding the connector/j's bin file into my JAVA_HOME path.

I'll try this, though. Thanks.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JAVA_HOME environment variable should point to the root folder of the JDK.
The CLASSPATH environment variable is in fact only and only used when you execute java.exe or javac.exe without the -cp, -classpath or -jar arguments.
 
Keith Wegner
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke Scholtz wrote:The JAVA_HOME environment variable should point to the root folder of the JDK.
The CLASSPATH environment variable is in fact only and only used when you execute java.exe or javac.exe without the -cp, -classpath or -jar arguments.

My JAVA_HOME is pointing there.

 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is not the root cause of the problem by the way.

You said that you added the JAR file to the JAVA_HOME, which makes completely no sense. I just wanted to rectify that.
 
Keith Wegner
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke Scholtz wrote:Which is not the root cause of the problem by the way.

You said that you added the JAR file to the JAVA_HOME, which makes completely no sense. I just wanted to rectify that.

I agree that it makes no sense - I found the idea here:

http://www.stardeveloper.com/articles/display.html?article=2003090201&page=4

"Among the extracted files will be a JAR file with a name like 'mysql-connector-java-3.0.8-stable-bin.jar'. Copy this file to your %JAVA_HOME%/jre/lib/ext folder which on my system happens to be D:\j2sdk1.4.2\jre\lib\ext>.

You should also add the complete path to this JAR file in your CLASSPATH environment variable. ..."
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ough, things get more worse. Physically placing the JAR file somewhere in the /lib of the JDK is really a bad practice. You shouldn't let your application depend that much on the JDK used. Also, if you have done that, then specifying its path in the classpath either would make completely no sense (simply because the JDK's lib folder is by default already covered by the classpath!).

As pointed out by others, just add it as external library in the build path of your Eclipse project. That's all. There is really no need to do all that nasty stuff outside the IDE.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic